Skip to content

Instantly share code, notes, and snippets.

@sambatlim
Created August 27, 2020 09:52
Show Gist options
  • Save sambatlim/f75fd26752668ab7dfbe9461925649ce to your computer and use it in GitHub Desktop.
Save sambatlim/f75fd26752668ab7dfbe9461925649ce to your computer and use it in GitHub Desktop.
simple javascript closure code
/// closure in javascript
// using parentheses
{
const value = 0
}
//console.log(value);
// closure function
// method 1
(()=>{
console.log('hello');
})();
// method 2
function makeFunc() {
var name = 'Mozilla';
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
myFunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment