Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. // Sync callback
  2. function greetings(callback) {
  3. callback();
  4. }
  5. greetings(() => { console.log('Hi'); });
  6. moreWork(); // will run after console.log
  7.  
  8. // Async callback
  9. const fs = require('fs');
  10. fs.readFile('/file.md', function callback(err, data) { // fs.readFile is an async method provided by Node
  11. if (err) throw err;
  12. console.log(data);
  13. });
  14. moreWork(); // will run before console.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement