What is a “closure” in JavaScript? Provide an example



What is a “closure” in JavaScript? Provide an example..

Answer / hrpatelsoft@gmail.com

var globalVar = "xyz";

(function outerFunc(outerArg) {
var outerVar = 'a';

(function innerFunc(innerArg) {
var innerVar = 'b';

console.log(
"outerArg = " + outerArg + "
" +
"innerArg = " + innerArg + "
" +
"outerVar = " + outerVar + "
" +
"innerVar = " + innerVar + "
" +
"globalVar = " + globalVar);

})(456);
})(123);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

How do you implement Ajax using hide() function in JQuery?

2 Answers   QuinStreet,


How do you reverse a string in javascript?

0 Answers  


How do you name a variable in javascript?

0 Answers  


Name some of the Javascript frameworks?

0 Answers  


what is the difference between window & document in javascript?

0 Answers  






How to validate a form in javascript?

0 Answers  


Expand BOM and explain it?

0 Answers  


What value does prompt() return if the user clicked the cancel button?

0 Answers  


Are there any training Institutions on iphone Automation testing?

0 Answers  


What is the main difference between Client side JavaScript and and Server side Java Script?

7 Answers   Ramco,


How many days it will take to learn javascript?

0 Answers  


What is the function of javascript?

0 Answers  


Categories