InterviewSolution
Saved Bookmarks
| 1. |
What do you mean by Error-First Callback? |
|
Answer» The “error-first” callback is also known as an “errorback”, “errback”, or “node-style callback”. Error-first callbacks are utilized to pass ERRORS and data too. You need to pass the error as the main parameter, and you MUST verify whether something went wrong. Additional arguments are utilized to pass data. There are two rules for defining an error-first callback:
Code example is as below:- fs.readFile(filePath, FUNCTION(err, data) { if (err) { // handle the error, the return is IMPORTANT here // so execution stops here return console.log(err) } // use the data object console.log(data) }) |
|