InterviewSolution
Saved Bookmarks
| 1. |
What are callbacks in JavaScript? |
|
Answer» In JavaScript, you can pass a FUNCTION to another function as an argument. A callback is a function passed as an argument into another function for executing later. JavaScript callback functions can be USED SYNCHRONOUSLY as well as asynchronously. Below is a simple example of callback functions in JavaScript. function postProcessing(result) { console.log(‘PROCESSING is over! The result returned is: ’ + result); } function addNumbers(a, b, NEXT) { let sum = a + b; next(sum); }addNumbers(10, 5, postProcessing); The output of the above code will be: Processing is over! The result returned is: 15 |
|