Skip to content

Instantly share code, notes, and snippets.

@dineshdeveloper1
Created September 28, 2023 04:15
Show Gist options
  • Save dineshdeveloper1/72be80106cf054bd4b6718b0c87f3159 to your computer and use it in GitHub Desktop.
Save dineshdeveloper1/72be80106cf054bd4b6718b0c87f3159 to your computer and use it in GitHub Desktop.
Asynchronous Data in Node
//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