InterviewSolution
| 1. |
Explain Higher Order Function in JavaScript? |
|
Answer» Default parameters are the parameters, which are used if we don’t pass the value to that argument in a function while CALLING it. Earlier to ES6, it was a BIT difficult to handle a situation like this. In the below example if user didn’t SUPPLIED a value to argument , we check inside the function “add” if “a” has a value or assign 0 to it. Same is done for “b”. So, now we can handle all THREE situation successfully like when we pass no arguments, or pass only value of ‘a’ or pass only value of ‘b’. The same can be done in ES6 by changing the parameter to contain the default value. Re-writing the above with ES6 default parameters. |
|