Question 19
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
let x = (1, 2, 3);
let y = (x++, x * 10);
console.log(x, y);
- A 4 40 Correct
- B 3 30
- C 1 10
- D 4 30
Correct Answer: Option A
The comma operator evaluates each operand and returns the last one: x = 3. Then x++ makes x 4, and the value of the whole expression is x * 10 = 40.
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!