Created
April 3, 2020 14:45
-
-
Save manojnaidu619/b9570d7268c52f21c2b7ee8d30720b3a to your computer and use it in GitHub Desktop.
Code snippet to demonstrate callback functions(async run) pattern
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
const addFunction = (a, b, callback) => { | |
setTimeout(() => { | |
const sum = a+b | |
callback(sum) | |
},1000) | |
} | |
addFunction(1, 2, (sum) => { | |
console.log(sum) | |
}) | |
console.log("This line prints first before computing sum...") | |
// to run this file -> node nodeCallbackDemo.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment