4 ms·
Some languages have one thing, an expression, and you compute the value of an expression by computing the value of its sub-expressions in a defined order. Thus,
by raganwald 14y ago
Some languages have one thing, an expression, and you compute the value of an expression by computing the value of its sub-expressions in a defined order. Thus, JavaScript does not define the result in “some arbitrary way,” it defines the result in the same simple way that holds throughout the language, the same way that Ruby and Lisp and a jillion other languages compute the value of expressions.
C has two things, an expression, and a statement, and you cannot compute the value of a statement by evaluating its sub-expressions in a defined order. trying it out in the interpreter or compiler is dangerous with an undefined result, because you could get one result today and another tomorrow.
It’s a “trick” in the sense that the simplest explanation of what should happen is not what happens.