HardMisc Quirks💻 Output Question

Comma Operator Evaluation

💡

Hint

Pay attention to the operator precedence and the order of evaluation in the given expression

What does this output?

let a = (1 + 2, 3 + 4);
console.log(a);

Correct Output

7

Why this output?

The comma operator evaluates each expression from left to right and returns the value of the rightmost expression. In this case, (1 + 2) evaluates to 3 and (3 + 4) evaluates to 7. Since the comma operator returns the value of the rightmost expression, the value of 'a' is 7.

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz