Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Closures in javascript?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 119
    Comment on it

    Whenever we defined a function within another function, the inner function has accessibility for the variables in the outer function.


    Following is the example of closure.

    function mainFunction(outerData) {
      var mainFuncData = 3;
    
      function innerFunction(innerFuncData) {
        console.log(outerData + innerFuncData + (++mainFuncData)); // will alert 16
      }
    
      innerFunction(10);
    }
    
    mainFunction(7); //17
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: