- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Promises
JavaScript Asynchronous
JavaScript Promises
A promise is an object representing a value that is not ready yet.
Instead of passing a callback in, you get an object back and attach handlers to it.
That small change is what lets asynchronous code be chained rather than nested.
Example
Example
javascript
const promise = new Promise(function (resolve) {
setTimeout(function () {
resolve("Ada");
}, 10);
});
promise.then(function (name) {
console.log("got " + name);
});