Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created April 3, 2020 14:45
Show Gist options
  • Save manojnaidu619/b9570d7268c52f21c2b7ee8d30720b3a to your computer and use it in GitHub Desktop.
Save manojnaidu619/b9570d7268c52f21c2b7ee8d30720b3a to your computer and use it in GitHub Desktop.
Code snippet to demonstrate callback functions(async run) pattern
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