Home » Interview » Technology

What is an error-first callback ?

Correct Answer: Error-first callbacks are used to pass errors and data as well You have to pass the error as the first parameter, and it has to be checked to see if something went wrong Additional arguments are used to pass data fsreadFile(filePath, function(err, data) { if (err) { // handle the error, the return is important here // so execution stops here return consolelog(err) } // use the data object consolelog(data) })

← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion