Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Last active February 25, 2020 19:40
Show Gist options
  • Save munkacsitomi/c84db5038a0181b85db5af1f77664f4b to your computer and use it in GitHub Desktop.
Save munkacsitomi/c84db5038a0181b85db5af1f77664f4b to your computer and use it in GitHub Desktop.
Closures
const outerValue = 'samurai';
let later;
function outerFunction() {
const innerValue = 'ninja';
function innerFunction() {
console.log(outerValue === 'samurai', 'I can see the samurai.');
console.log(innerValue === 'ninja', 'I can see the ninja.');
}
later = innerFunction;
}
outerFunction();
later();
const samurai = () => 'samurai here';
const ninja = () => {
const hiddenNinja = () => 'ninja here';
return hiddenNinja();
};
console.log(samurai() === 'samurai here', 'A samurai');
console.log(ninja() === 'ninja here', 'A ninja');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment