async/await
const multiply = (number1, number2) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(number1 * number2);
}, 1000);
});
};const result = await multiply(2, 2);
console.log(result);const main = async () => {
const result = await multiply(2, 2);
console.log(result);
};
main();const main = async () => {
let result = await multiply(2, 2);
result = await multiply(result, 2);
result = await multiply(result, 2);
console.log(result); // 16
};
main();Last updated
