This error occurs when the comma is interpreted as “comma operator” and not comma within arrays, objects, etc.
Comma operator evaluates each expression separated by comma and returns the last value.
const foo = (1, 2, 3) // returns 3
In this example, 3 will be assigned to foo. But it is highly likely that author thought (1, 2, 3) will be assigned like python tuple. So this error exists.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator
So if you encountered this error, chances are there are some mistakes in your array/object/etc and it is interpreted as "comma operator".
Example code which causes this error.
const foo = (expr) => {
const bar = ""
const baz = ""
switch (expr) {
case 'Oranges', 'Mangoes': // error, you can't use comma for switch
break;
case 'Papayas':
break;
}
{ bar, baz } // You forgot to write return. Javascript thinks this is comma operator.
}