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 does === mean in js?
Is javascript a dynamic language?
Explain the steps for connecting the system to Internet.
What are the different functional component in javascript?
How to redirect a page to another page in javascript?
What is trim whitespace google sheets?
What is a function constructor?
What is Date object in JavaScript?
How do I turn on javascript on my phone?
What is a fixed-width table and its advantages?
What are global variables in javascript?
What is innertext javascript?
What are the ways to emit client-side javascript from server-side code in asp. Net?
List out the Mouse Events?
Explain how to detect the operating system on the client machine?