LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 19

The comma operator Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links