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
Is javascript client side or server side?
What output will this program produce System.out.println(x+"+"+y+"="+(x+));
What is javascript in simple terms?
Why is my javascript function not defined?
How do you define a class and its constructor?
How can an HTMLCollection be traversed?
What is meant by object oriented programming?
How to add multiple functions in javascript?
What is the reason for wrapping the entire content of a javascript source file in a function book?
Why do we need currying?
How to create an input box?
Is everything in javascript asynchronous?
Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?
What is the use of blur function in JavaScript?
Entire content of a JavaScript source file in a function block?