- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Async Callbacks
JavaScript Asynchronous
JavaScript Async Callbacks
An asynchronous callback is a function that runs once slow work has finished.
Before promises existed, this was the only way to handle a result that arrives later.
It works, but it nests badly once one job depends on another.
Example
Example
javascript
function loadUser(callback) {
setTimeout(function () {
callback("Ada");
}, 10);
}
loadUser(function (name) {
console.log("got " + name);
});