DEV Community

Shubham_Baghel
Shubham_Baghel

Posted on

Closure in Javascript

closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function’s variables, and it has access to the global variables.

code

function dosomecalculations() {var a=5;var b=4;function multiply() { var result = a*b; return result; } return multiply; } var output = dosomecalculations(); //code for output console.log("The result:", output());

Top comments (0)