closures in JavaScript - mmedrano9438/peripheral-brain GitHub Wiki

a closure gives you access to an outer function's scope (in this case you have access to variable 'name') from an inner function. function init() { var name = "Mozilla"; // name is a local variable created by init function displayName() { // displayName() is the inner function, that forms the closure console.log(name); // use variable declared in the parent function } displayName(); } init();