What is a “closure” in JavaScript? Provide an example
Answer / 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 |
Why are callbacks used?
What are undeclared and undefined variables?
what is the difference between let, var, and const?
What are the different types of errors supported by javascript?
How Can I get facebook fans/likes?
How to get the contents of an input box using javascript?
Give an example of closure?
How to enabled 'Strict' mode in JavaScript?
What is the difference of "settimeout" function and setinterval functions in javascript
How can you get the reference of a caller function inside a function?
What is JavaScript?
how can we generate alert message without referashing page in asp.net with language vb.net and script use in java script .means with out referash the page message in java alert