How to get a value out of a promise?

Nikhil Nambiar
Jan 28, 2020

--

Here is the promise:

let promise = new Promise(function(resolve, reject) {
resolve("I am a man who keeps his word")
})

There are 2 ways to get a value out of a promise.

#1: with .then() (traditional)

promise.then(function(value) {
console.log(value)
})
// I am a man who keeps his word

#2: With Async / Await

let whoAreYou = await promiseconsole.log(whoAreYou)
// I am a man who keeps his word

--

--

Nikhil Nambiar
Nikhil Nambiar

No responses yet