0

I really don't know what to google to find out the name for this syntax:

(1,2) seems to evaluate to 2

(1,2,3,"cake") seems to evaluate to "cake". etc

This is sometimes useful in anonymous functions in Array.reduce, where you need to perform a sequence of operations (say an increment) and also return the element on the right.

But where can I read about it and what's it called?

jsstuball
  • 4,104
  • 7
  • 33
  • 63
  • 3
    I'm not an expert but... Isn't just a good old [comma operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator)? – Álvaro González Mar 28 '20 at 15:50

1 Answers1

1

It's just the comma operator: it evaluates each of its operands (from left to right) and returns the value of the last operand.

ZER0
  • 24,846
  • 5
  • 51
  • 54