Javascript Comma Operator

Introduction

The comma operator allows execution of more than one operation in a single statement:

let num1 = 1, num2 = 2, num3 = 3; 

The comma operator is used in the declaration of variables normally.

It can also be used to assign values.

When used in this way, the comma operator always returns the last item in the expression:

let num = (5, 1, 4, 8, 0);  // num becomes 0 

In this example, num is assigned the value of 0 because it is the last item in the expression.




PreviousNext

Related