Question 9
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
var total = 10;
function update() {
total = 20;
var local = 5;
}
update();
console.log(total, typeof local);
- A 10 undefined
- B 20 number
- C 10 number
- D 20 undefined Correct
Correct Answer: Option D
update() has no local total, so the assignment changes the outer one. local is a var of update() and is not visible outside.
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!