Closure in Javascript

shubhamb

Shubham_Baghel

Posted on January 17, 2020

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());
💖 💪 🙅 🚩
shubhamb
Shubham_Baghel

Posted on January 17, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Closures in JS 🔒
javascript Closures in JS 🔒

June 26, 2024

Object Patterns in Javascript
javascript Object Patterns in Javascript

February 3, 2020

70 JavaScript Interview Questions
javascript 70 JavaScript Interview Questions

January 3, 2020

Closure in Javascript
javascript Closure in Javascript

January 17, 2020