What is a “closure” in JavaScript? Provide an example
Answer Posted / 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 View All Answers
How do I write script-generated content to another window?
What does js stand for?
What is the use of a map object in javascript?
Write the code for adding new elements dynamically?
What is memory leak in javascript?
What is the Infinity property used for in Javascript?
What do “1”+2+4 evaluate to?
What is the difference between "var" and "let" keywords?
Difference between the substr() and substring() in JavaScript?
What are different types of inheritence? Which inheritance is followed in javascript.
What is the use of dom?
what is the difference between wrappers and primitives es: diff between int i=200 in primitives and integeri = new integer(54)
What is use of settimeout function in javascript?
Which built-in method sorts the elements of an array?
What is a null variable?