I’m writing a JavaScript parser and while testing it on the prototype.js library, it threw up an error on this code:
line 4000:
while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) {
soFar = m[3];
parts.push( m[1] );
if ( m[2] ) {
extra = m[3];
break;
}
}
I reduced it down to this:
while ( (a, b) == c ) {}
Is this really valid JavaScript? According to ECMA-262, a while loop has this syntax:
while ( Expression ) Statement
What sort of expression is (a, b) == c? I didn’t think tuples were supported in JavaScript?
That’s not a tuple; that’s the comma operator (also see Wikipedia). The comma operator evaluates the first operand and then the second operand and yields the value of the second.