
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is Comma Operator (,) in JavaScript?
The comma operator in JavaScript evaluates each of its operands. It returns the value of the last operand. Add multiple expressions using the comma operator.
Syntax
The following is the syntax −
expression1,expression2, ……expression
Yes, you can use the comma operator to add multiple parameters in a for loop −
for (var a = 0, b =5; a <= 5; a++, b--)
You can also use the comma operator in a return statement. Process before returning using comma −
function myFunc() { var a = 0; return (a += 1,a); }
Above you can see the value of a will process and then it will be returned.
- Related Articles
- What is Comma operator in C++?
- When is the comma operator useful in JavaScript?
- Comma operator in C/C++
- What is increment (++) operator in JavaScript?
- What is decrement (--) operator in JavaScript?
- What is Conditional Operator (?:) in JavaScript?
- What is typeof Operator in JavaScript?
- What is Modulus Operator (%) in JavaScript?
- What is Multiplication Operator (*) in JavaScript?
- What is Addition Operator (+) in JavaScript?
- What is Assignment Operator (=) in JavaScript?
- What is spread Operator (...) in JavaScript?
- What is Subtraction Operator (-) in JavaScript?
- A comma operator question in C/C++ ?
- What is an exclamation “!” operator in JavaScript?

Advertisements