Skip to content

Instantly share code, notes, and snippets.

@PabloRegen
Created April 11, 2019 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PabloRegen/fe9451bcce1fc64e427dfdae42d0a16c to your computer and use it in GitHub Desktop.
Save PabloRegen/fe9451bcce1fc64e427dfdae42d0a16c to your computer and use it in GitHub Desktop.
// Sync callback
function greetings(callback) {
callback();
}
greetings(() => { console.log('Hi'); });
moreWork(); // will run after console.log
// Async callback
const fs = require('fs');
fs.readFile('/file.md', function callback(err, data) { // fs.readFile is an async method provided by Node
if (err) throw err;
console.log(data);
});
moreWork(); // will run before console.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment