The main issue IMHO is that the meaning of comma is dependent on context.
If you're in a function call, comma is used to separate arguments:
f(arg1, arg2);
If you want to use the comma operator to separate expressions in a single argument, you need an extra set of parentheses:
f((arg1, arg2));
And in variable declarations, it separates variables being declared:
let v1 = foo, v2;
is a declaration of two variables, it's not the comma operator; again, you'd need parentheses:
let v1 = (foo, v2);
More generally, comma is not idiomatically used to separate statements. It's useful when you need to sequence multiple operations in a place where only one statement is allowed, e.g. the header of for()
or while()
. But top-level statements should be separated with semicolon, not comma. Other programmers will find it easier to read your code if you follow common conventions like this.
I wouldn't be surprised if the comma operator is used more often in programming puzzles and quizzes than in actual production code.