Promise is the result of an asynchronous operation
(available since ES6 in 2015).Promise.resolve(42)
Promise(status="fulfilled", result=42)
new Promise(function (resolve, reject) {
resolve(42);
})
Promise(status="fulfilled", result=42)
Promise.resolve(42)
.then((v) => v + 58)
.then(print);
new Promise(function (resolve, reject) {
throw new TypeError('oops!')
})
Promise(status="rejected", result=TypeError("oops!"))
function wait(millis, value) {
if (arguments.length < 2) {
return wait.bind(null, millis);
} else {
return new Promise(function (resolve, reject) {
setTimeout(() => resolve(value), millis);
});
}
}
Promise.resolve('done!')
.then(wait(1000))
.then(print);
The console allows you to interact with the course material and examples. Use the following keys:
A special logging function is also available: