Friday, September 5, 2025
HomeLanguagesJavascriptJavaScript Comma Operator

JavaScript Comma Operator

Comma Operator (,) mainly evaluates its operands from left to right sequentially and returns the value of the rightmost operand. A comma operator is used as a separator for multiple expressions at a place that requires a single expression. When a comma operator is placed in an expression, it executes each expression and returns the rightmost expression.

Syntax:

Expression1, Expression2, Expression3, ...so on

In the above syntax, multiple expressions are separated using a comma operator. During execution, each expression will be executed from left to right and the rightmost expression will be returned.

 

Example 1: Below is an example of the Comma operator.

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

Example 2: The most useful application of the comma operator is in loops. In loops, it is used to update multiple variables in the same expression.

javascript




for (let a = 0, b =5; a <= 5; a++, b--) {
    console.log(a, b);
}


Output

0 5
1 4
2 3
3 2
4 1
5 0

We have a complete list of JavaScript Operators, to check those please go through the Javascript Operators Complete Reference article. 

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS