Shadowing and IIFE 4

 4th Day                                                                                             See the source image

     

  • Hey Guys Welcome to my 4th day of Blog writing, I'm last year student from Shiva ji University, Kolhapur. This post has been posted for beginners and professionals both and new post will have to be updated on Every Saturday & Sunday.

          Q. Guys, What is Shadowing and how to prevent it ?

         A. Shadowing is one type of features of  JavaScript. Let's see example:

                 Input: 

            Explanation:                                                                                                                                 Above mentioned simple Example, We create a function fun()1

          and invoked fun1(); it given as output "This is fun1".

                        Output:

For Function:

        Note:

        Suppose that by mistake we created same function more than one

       times in that case 2nd function will become overlap on 1st function 

       this concept is known as Shadowing.

                          Example  Input:

            Explanation:                                                                                                                          Above two same function has been created and invoked then after 
   2nd time created function overlap on 1st so 2nd will be show and 
   1st will become hide.

                             Output: 


                                                      For Variable:
    In case of variable, more than one variable has been declared but in that 
    case both will  show output but different 1st variable will show 1 while 2nd                            will 0.
                                  Input:
                                    

                               Output:                For 1st Variable
                             
                              For 2nd Variable                    
                     
     Immediately Invoked Function Expression(IIFE)
  •      It is Prevent to the shadowing in program. Its is defined as 
  •     (function() { Statements })(); For Example:

                    Input: 

 

          Output: 
                        

                
Thank you...

ليست هناك تعليقات:

إرسال تعليق