Skip to main content

Command Palette

Search for a command to run...

Closure function

Updated
1 min readView as Markdown
Closure function

https://www.codingem.com/javascript-closures/

A Closure function is a function that can access to the variables declared in the outer context, including global variables.

In JavaScript, closure means an inner function can access variables that belong to the outer function.

This is not a closure:

//Named function
function greetings() { //this is not a closure function.
    return ‘omar’;
}

//anonimous function
var greetings2 = function () { //this is not a closure function.
    return ‘rami;
}

greetings(); //omar
greetings2(); //rami

More from this blog

Omar's blog

135 posts