Question 7
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
let calls = 0;
const makeDefault = () => (++calls, "default");
const [p = makeDefault(), q = makeDefault()] = ["given"];
console.log(p, q, calls);
- A given default 2
- B default default 2
- C given default 1 Correct
- D given undefined 0
Correct Answer: Option C
Defaults are evaluated only when the value is undefined. p receives "given", so its default never runs; q is missing, so makeDefault runs once.
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!