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
What value does prompt() return if the user clicked the cancel button?
What are the difference between javascript and jquery?
What is the scope variable in javascript?
What is a method in javascript?
What typeof returns for a null value?
What is use of JavaScript and jquery?
What is the output of 10+20+”30″ in JavaScript?
What is NaN?
What is stack queue?
Is jquery easier than javascript?
What is are the types of the pop up box es available in javascript?
How to submit a form using JavaScript by clicking a link?
What are the variable naming conventions in javascript?
How to make a function in javascript?
In Java coding we will write a public static void main()? Why won't we write as a static public void main()