Question 11
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
var count = 5;
(function () {
var count = 1;
count++;
})();
console.log(count);
- A 2
- B 6
- C 1
- D 5 Correct
Correct Answer: Option D
The IIFE declares its own count, which shadows the outer one and disappears when the function returns.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!