Advertisement
728x90
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
1for (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
1function myFunction() {
2 var a = 1;
3 return (a += 10), a; // 11
4 }Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 80
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
251of476