JavaScript Comma Operator (original) (raw)

Last Updated : 23 Nov, 2024

**JavaScript Comma Operator mainly evaluates its operands from left to right sequentially and returns the value of the rightmost operand.

JavaScript `

let x = (1, 2, 3); console.log(x);

`

Here is another example to show that all expressions are actually executed.

JavaScript `

let a = 1, b = 2, c = 3;

let res = (a++, b++, c++);

console.log(res); console.log(a, b, c);

`

Here is an example with function calls.

javascript `

function Func1() { console.log('one'); return 'one'; } function Func2() { console.log('two'); return 'two'; } function Func3() { console.log('three'); return 'three'; }

// Three expressions are // given at one place let x = (Func1(), Func2(), Func3());

console.log(x);

`

Output

one two three three

Similar Reads

JavaScript Basics







JS Variables & Datatypes






JS Operators













JS Statements







JS Loops







JS Perfomance & Debugging




JS Object







JS Function








JS Array