Created
September 28, 2023 04:15
-
-
Save dineshdeveloper1/72be80106cf054bd4b6718b0c87f3159 to your computer and use it in GitHub Desktop.
Asynchronous Data in Node
This file contains 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
//js executed in the sequence they are called | |
function myFirst() { | |
myDisplayer("Hello"); | |
} | |
function mySecond() { | |
myDisplayer("Goodbye"); | |
} | |
myFirst(); | |
mySecond(); | |
// | |
let a = 20; | |
let b = 0 | |
setTimeout(()=>{ | |
b = 20 | |
}, 1000) | |
console.log(a+b) | |
----------------------------------------------------------------------------------- | |
let a = 20; | |
let b = 0 | |
let waitingData = new Promise((resolve, reject)=>{ | |
setTimeout(()=>{ | |
resolve(50) | |
}, 2000) | |
}) | |
waitingData.then((data)=>{ | |
console.log(a+data) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment