InterviewHubPRO
Section Overview
Q255

Question 255 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

49%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What is the advantage of the comma operator

It is normally used to include multiple expressions in a location that requires a single expression. One of the common usages of this comma operator is to supply multiple parameters in a for loop. For example, the below for loop uses multiple expressions in a single location using comma operator,

javascript
  for (var a = 0, b =10; a <= 10; a++, b--)

You can also use the comma operator in a return statement where it processes before returning.

javascript
  function myFunction() {
    var a = 1;
    return (a += 10), a; // 11
  }