Tyler Buchea

Tyler Buchea

Simple Promises Example In JavaScript

Simple Promises Example In JavaScript

An asynchronous function is just a regular function that returns a Promise instead of a Number, String, etc. function asynchronousFunction() { const executorFunction = (resolve) => { setTimeout(() => resolve("foo"), 2000); }; return new Promise(executorFunction); } function synchronousFunction() { return "bar"; } asynchronousFunction() // foo .then(console.log) .catch(console.log); console.log(synchronousFunction()); // bar // console.log output:
1 min read