Created
May 15, 2021 20:33
-
-
Save helabenkhalfallah/9010b6d123ebbb171dac2c381c32c47f to your computer and use it in GitHub Desktop.
JS Closure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const outerFunc = () => { | |
// the outer scope | |
let outerVar = 'I am from outside!'; | |
const innerFunc = () => { | |
// the inner scope | |
console.log(outerVar); | |
} | |
return innerFunc; | |
} | |
const myInnerFunc = outerFunc(); | |
myInnerFunc(); // 'I am from outside!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment