A closure gives you access to an outer function's scope from an inner function. A closure is a function having access to the parent scope, even after the parent function has closed. See the live result:- https://playcode.io/1941383 //Clousure var sum = function ( a ){ console . log ( "Live Clousure views - " + a ); var c = 2 ; return function ( b ){ return a + b + c; //lexical scope } } //this function execute two times - one is - sum(1) and other one is - sumAgain(3) //the value of a=1 and c=3 will be presist in the mermory. One call to sumAgain(3) then the result will be 6 (1+3+2) //that is called closure var sumAgain = sum ( 1 ); //calling and set the value of a=1 and c=2 in the memorey console . log ( sumAgain ( 3 )); //calling with value b=3. Now the result will be 6
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers