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
Which built-in method returns the calling string value converted to upper case?
What is the difference between window and document in Javascript?
How do you check if a value is a number in javascript?
How do I open javascript in browser?
What is difference between module.exports and export?
Explain javascript accessors ?
How to remove duplicates from javascript array?
How do I run javascript in chrome?
How to open url in a new tab in javascript?
What is the use of a map object in javascript?
How to encode and decode a url in javascript?
What is the use of a date object in javascript?
List html dom mouse events?
Text from your clipboard?
Is webassembly faster than javascript?