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's the Difference Between Class and Prototypal Inheritance?
What is a function constructor?
What is double exclamation point?
Are Javascript and JScript the same?
What is a function in javascript and how does it work?
Explain how can you submit a form using JavaScript?
What's the date object using javascript?
What are different types of inheritence? Which inheritance is followed in javascript.
List some unit testing frameworks javascript
can wwe trace a java program (class)
What are all the types of Pop up boxes available in JavaScript?
Explain why asynchronous code is important in javascript?
What is difference between undefined variable and undeclared variable?
What are all the looping structures in javascript?
What are the basic groups of dataypes in JavaScript?