Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

what is a closure in javascript

// A Closure gives you access to an outer function's scope from an inner function.
// Example
function myNameIs(name) {
  return function(){
  	console.log('Hi my name is ' + name);
  }
}

let maxine = myNameIs('Maxine');
let amber = myNameIs('Amber');

maxine();
amber();
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #closure #javascript
ADD COMMENT
Topic
Name
4+5 =