whatstheoutput_

#83: let x = (1, 2, 3)

Topic: misc · Difficulty: ★

let x = (1, 2, 3);
console.log(x);

Output

3

Why

The comma inside those parentheses is not separating function arguments or array items — it's the comma OPERATOR. It evaluates each of its operands left to right, throws away every result except the last one, and yields only that final value as the value of the whole expression. So (1, 2, 3) evaluates 1, then 2, then 3, discarding the first two, and the expression's value is simply 3. This operator shows up rarely in real code, mostly inside for-loop headers where you need to run two updates in one clause, like for (i = 0, j = 10; ...).

More misc puzzles

Play today's puzzle →