What is the correct way to interpret this complicated javascript expression?
some_condition ? a = b : c = d = e;
Following operator precedence rules, I would expect it to be:
(some_condition ? a = b : c) = d = e;
But it seems that the grouping is actually:
EDIT: (The original grouping was unclear. See below for update)
EDIT: some_condition ? a = b : (c = d = e);
Why is this so? (And no I did not write that code)
EDIT: This seems to suggest that in Javascript to say ?:
have higher precedence than =
is not entirely true. As a further example:
x = y ? a = b : c = d = e;
If ?:
have higher precedence than =
(as in C) then the grouping would be
x = ((y ? a = b : c) = (d = e));
but rather (from the answers) what we have is
x = (y ? a = b : (c = d = e));
The relative precedence of ?:
and =
seems to depend on where they appear in the expression
some_condition ? (a = b) : (c = d = e);
– Melburn