const createPrinter() {
const name = 'Alex'
const printName = () => {
console.log(name)
}
return printName
}
const myPrinter = createPrinter()
myPrinter() // Alex
This function that was return from from
createPrinter
function is called a closure. // Here is printName
Closure is a combination of a function and the environment where it was declared.
Comments
Post a Comment