InterviewSolution
| 1. |
What is IIFE in JavaScript? |
|
Answer» A callback function, also known as a higher-order function, is a function that is passed to another function as a parameter, and the callback function is executed inside the that Function. Callback function are USED everywhere in JavaScript. In JavaScript, functions are first-class citizens. They can be “stored in variables, passed as arguments to functions, created WITHIN functions, and returned from functions”. Let’s look at the example below. Here we call function mainFunc with function “x” as argument and then from inside mainFunc, calling it after some CONSOLE log. When we use anonymous function inside our function call for callback LIKE in the below code. The in-built for Each, map, reduce, filter uses callback functions internally. CHECK the below example and here we are passing a function, just like above calc code. |
|