-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosure.js
More file actions
24 lines (21 loc) · 848 Bytes
/
closure.js
File metadata and controls
24 lines (21 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Closure : Function Bind Withs Their Required Data / Lexical Scope / Surrounding State.
// let firstName = "Sunil";
// function outerFunction(){
// let firstName = "Priyanshu";
// function innerFunction(){
// // let firstName = "Sumit";
// console.log("My Name Is : ",firstName);
// }
// innerFunction();
// }
// outerFunction();
// Closures Property Shown
function outerFunction(){
let firstName = "Priyanshu";
function innerFunction(){
console.log(firstName);
}
return innerFunction;
}
let inner = outerFunction(); // After Calling the outerFunction the firstName memory is free after the function call and now if we call the inner() it prints undefined? but it prints Priyanshu because the innerFunction is Binds with the Required Field firtName. this is we called closures.
inner();