Question 18
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
let i = 0;
const o = { [`item${++i}`]: i, [`item${++i}`]: i };
console.log(o);
- A { item1: 0, item2: 1 }
- B { item2: 2 }
- C { item1: 2, item2: 2 }
- D { item1: 1, item2: 2 } Correct
Correct Answer: Option D
Each key expression is evaluated before its value, left to right: ++i makes i 1 for the first key, so its value is 1; then 2 for the second.
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!