-2

What is comma operator in JavaScript. If I execute

var a = 1;
var b = 2;
a,b

I get

2
Jyoti Puri
  • 1,326
  • 10
  • 17

1 Answers1

4

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.

From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

More on: http://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/

Diana Nassar
  • 2,303
  • 14
  • 17