what is closure in javascript
function OuterFunction() {
var outerVariable = 100;
function InnerFunction() {
alert(outerVariable);
}
return InnerFunction;
}
var innerFunc = OuterFunction();
what is closure in javascript
function OuterFunction() {
var outerVariable = 100;
function InnerFunction() {
alert(outerVariable);
}
return InnerFunction;
}
var innerFunc = OuterFunction();
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us