Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

closure in javascript

//Closures
Closures means a function bind together with its lexical environment
                           	OR
You can say a function along with its lexical scope bundle together forms
a closure
                            OR
In other words, a closure gives you access to an outer function's
scope from an inner function.
//Example
function x(){
  var a = 7;
  function y(){    //function y bind with its lexical enviroment
    console.log(a); 
  }
  a = 100;
  return y;
}
var z = x();
console.log(z) //Output is 100 
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #closure #javascript
ADD COMMENT
Topic
Name
3+8 =