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
Why do we need javascript?
What is scope variable in javascript?
What is a fixed-width table and its advantages?
What is the difference between null & undefined?
What is the use of document object?
What are the problems associated with using javascript, and are there javascript techniques that you discourage?
How Does Function Hoisting Work in JavaScript?
How can javascript make a web site easier to use? That is, are there certain javascript techniques that make it easier for people to use a web site?
What is createtextnode?
Which built-in method returns the length of the string?
What do mean by NULL in Javascript?
How does typeof operator work?
What is npm repository?
How to set the cursor to wait?
What is javascript ‘strict mode’?