Created
August 27, 2020 09:52
-
-
Save sambatlim/f75fd26752668ab7dfbe9461925649ce to your computer and use it in GitHub Desktop.
simple javascript closure code
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
/// 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