Yes, it does, and it works fine in Chrome:
var a, b, c; a = 6; b = 7; c = a !== b ? (a = 1, b = 2) : (a = 2, b = 1); console.log("a = " + a); console.log("b = " + b); console.log("c = " + c);
I am not saying that this is a remote idea in the code that people should read. :-) I expect jamietre to be right in the comments when he / she says that this is similar to the result of the evaluation.
An operator is a binary operator (an operator that takes two operands). It evaluates the left operand (thus causing any side effects, such as assignment), discards the result, then calculates its right operand (thus causing its side effects, if any) and accepts this result as its result. If you have several comma operators in a string, the general expression is evaluated in order from left to right, and the end result is the value obtained by evaluating the right-most operand.
And, of course, you know the conditional operator (the triple operator - one takes three operands) is used to select one of two subexpressions to evaluate based on the original expression.
So, this line is very ... expressive ... which contains only seven * different expressions in it.
So, in this example, the result of the general expression is 2 if a !== b initially, or 1 if a === b initially, with side effects of setting a and b .
These are side effects that make this, in my opinion, a dubious choice. And, of course, there is no reason to use a comma operator if the left operand has no side effects.
* Yes, seven of them are packaged in this common ternar:
a !== b- first expression for comma
a = 1b = 2- second expression for comma
a = 2b = 1
Repeat your editing with the actual statement, which also works:
function test(a) { var b = 7, d = 1, e = 2, f = 3, g = 4, h = 5, i = 6; a!==0?b<0?(h=b/a,e=h-1,f=-2*b+2*a*e,i=-2*b+2*a*h,d=2*h*a-2*b-2*a):(h=b/a,e=h+1,f=2*b-2*a*e,i=2*b-2*a*h,d=-2*h*a+2*b):d=h=e=f=i=0; console.log("a = " + a); console.log("b = " + b); console.log("d = " + d); console.log("e = " + e); console.log("f = " + f); console.log("g = " + g); console.log("h = " + h); console.log("i = " + i); } test(0); test(1);
.as-console-wrapper { max-height: 100% !important; }
But wow, I hope that this will be reduced, because if a person wrote this, they should really deal with anyone who was supposed to support him later ...; -)