This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
An aync function that takes two numbers and performs some operations | |
*/ | |
performOperations(2,3).then(output => console.log(output)).catch(err => console.log(err)); | |
async function performOperations(a,b) { | |
let sum = await addTwoNos(a, b); | |
let doubleOfSum = await double(sum); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Suppose I want to add two numbers, then double it, then square that number, then add double it again. Using Promises. | |
*/ | |
addTwoNos(2, 3) | |
.then(sum => double(sum)) | |
.then(doubleOfSum => square(doubleOfSum)) | |
.then(square => double(square)) | |
.then(output => console.log(output)) | |
.catch(err => console.log(err)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Suppose I want to add two numbers, then double it, then square that number, then add double it again. | |
*/ | |
addTwoNos(2, 3, (sum) => { | |
double(sum, (doubleOfSum) => { | |
square(doubleOfSum, (square) => { | |
double(square, (doubleOfSquare) => { | |
console.log(doubleOfSquare) | |
}) | |
}) |
NewerOlder