In the code snippet below, what do a
and b
evaluate to?
This is a fun one. The weirdest part is probably the comma ,
operator.
If you’re not familiar, ,
evaluates each of its operands (from left to right) and returns the value of the last operand. This allows us to, in a single line, increase sum
by x
and return the square of x
. When finished, we get the sum
of the array as well as a new array of squares
.