Created
July 8, 2016 19:38
-
-
Save alejandrorangel/473e5b94c4fbe271386e35f521761884 to your computer and use it in GitHub Desktop.
Script to show the behavior of callbacks and promises
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
(()=>{ | |
console.log("start"); | |
secondFunction().then(function(secondNumber){ | |
console.log("result first promise "+secondNumber); | |
}); | |
myFunction((newNumber)=>{ | |
var lNumber = 20 + newNumber; | |
console.log(lNumber); | |
}); | |
console.log("end"); | |
})() | |
function myFunction(callback){ | |
console.log("callback"); | |
var mNumber = 2+3; | |
return callback(mNumber); | |
} | |
function secondFunction(){ | |
return new Promise(function(resolve, reject){ | |
console.log("promise"); | |
thirdFunction().then(function(thirdNumber){ | |
console.log("result second promise "+thirdNumber); | |
}) | |
console.log("end first promise"); | |
return resolve(2+15); | |
}); | |
} | |
function thirdFunction(){ | |
return new Promise(function(resolve, reject){ | |
console.log("second promise"); | |
return resolve(1234); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment