Skip to content

Instantly share code, notes, and snippets.

@tanisha03
Created February 2, 2020 12:56
Show Gist options
  • Select an option

  • Save tanisha03/bcdb7e6eb44a090a9efb8fe9cd873e67 to your computer and use it in GitHub Desktop.

Select an option

Save tanisha03/bcdb7e6eb44a090a9efb8fe9cd873e67 to your computer and use it in GitHub Desktop.
Understanding closures
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