Question 14
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const x = "outer";
function f(a = x) {
const x = "inner";
return a;
}
console.log(f());
- A inner
- B ReferenceError
- C outer Correct
- D undefined
Correct Answer: Option C
Defaults are evaluated in the parameter scope, which sits outside the function body. The body's x is not visible there, so a takes the outer x.
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!