Saturday, December 8, 2018

Benefit of function Expression

  
  Function statements
function double(x){
 console.log(2*x);
}
double(2); // invoke the function
Function expressions
var doubleFunction = function(x){
 console.log(2*x);
}
doubleFunction(2); // invoke the function

  
There are some benefits of function expressions over statements, for example they are anonymous functions, they can be used as closures, as arguments to other functions and as IIFEs.

No comments:

Followers

Link