[X]

The Comma Operator

luljs still works

A comma-separated expression evaluates all of it and returns the last.

In 2026: Still works, and it is rarely seen on purpose. The comma operator evaluates each expression left to right and yields the last one, so (1, 2, 3) is 3. It hides in minified code and in for loops. Do not confuse it with the commas in array literals or argument lists.

Where it came from: The comma operator evaluates each operand and returns the last, as MDN's comma operator page describes. MDN

<script>
document.write('<p><code>(1, 2, 3)</code> is <b>' + (1, 2, 3) + '</b></p>');
var x = (document.write('<p>The middle expression ran (this line), and...</p>'), 42);
document.write('<p><code>x = (writeThisLine(), 42)</code> gives x = <b>' + x + '</b></p>');
</script>
sandboxed demo · breaks nothing but itselfrestart

More in luljs

all 63 in luljs › · the whole library ›