Immediately Invoked Function Expression (IIFE)

IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined.
It is a design pattern which is also known as Self-Executing Anonymous Function and contains two major parts. The first is the anonymous function with lexical scope enclosed within the Grouping Operator (). This prevents accessing variables within the IIFE idiom as well as polluting the global scope.
The second part is creating the immediately executing function expression (), through which the JavaScript engine will directly interpret the function.

Immediately Invoked Function Expression (IIFE)

  • Avoid Creating Global variable and Functions
  • As it doesn‟t define variable and function globally so there will be no name conflicts
  • Scope is limited to that particular function

Pass by Value

  • JavaScript arguments are passed by value: The function only gets to know the values, not the argument’s locations.
  • If a function changes an argument’s value, it does not change the parameter’s original value.
  • Changes to arguments are not visible (reflected) outside the function.

Pass by reference

  • In JavaScript, object references are values.
  • Because of this, objects will behave like they are passed by reference:
  • If a function changes an object property, it changes the original value.
  • Changes to object properties are visible (reflected) outside the function.

Tagged : / / /
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x