Friday, August 28, 2020

Learn Shadowing in JavaScript and IIFE- Day 4


 In this articles, we learn about  Shadowing in JavaScript and IIFE.


1.Shadowing in JavaScript 

  • In a programming language, shadowing occurs when a variable is declared in certain scope has the same name defined on its outer scope.
  • In the inner scope, both variables scope overlap.
  • Simply shadowing means an exact copy of anything.


  • So, there are two concepts:

         1.Variable  Shadowing

         2. Function Shadowing

  • Outer variable or function is shadowed by the inner variable or function.
  • Inner variable or function is mask of outer variable or function.


Example:

Program:

Output:



2.IIFE:

  • IIFE stands for Immediately Invoke Function Expression.
  • IIFE is a way to execute functions immediately as soon as they are created.
  • IIFE contains parenthesis ()which are important here, these parenthesis contain expression not a statement.
  •  IIFE has a "function or variable" defined inside IIFE,can not be accessed outside the IIFE  block, thus preventing global scope from getting polluted.


Syntax:

( function () {

// function logic here.

}) ();


Example:

Program:


Output:






Thank you!!!!!!!!!!!!

No comments:

Post a Comment

Function in SQL -part 8

  In this blog we are going to understand  Sql function.   FUNCTION: A function is a database object in SQL Server. It accepts only input pa...