Created
February 2, 2020 12:56
-
-
Save tanisha03/bcdb7e6eb44a090a9efb8fe9cd873e67 to your computer and use it in GitHub Desktop.
Understanding closures
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
| function greet(fname){ | |
| return sayHello(lname){ //inner function | |
| return "Hello "+fname+lname; //access to the variable | |
| } | |
| } | |
| var greetTanisha=greet("Tanisha"); | |
| print(greetTanisha("Sabherwal")); | |
| // PRINTS "Hello TanishaSabherwal" | |
| // USING ES6 | |
| let greet = (fname) => { | |
| return (lname) => { //inner function | |
| return "Hello "+fname+lname; //access to the variable | |
| } | |
| } | |
| let greetTanisha=greet("Tanisha"); | |
| print(greetTanisha("Sabherwal")); | |
| // PRINTS "Hello TanishaSabherwal" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment