[...]
wouldn't mind a stab
No need to guess, read the spec.
that in interpreted language the whole thing
becomes if (isequal(a,b)) with no particular reason to prefer one order
over another. or maybe that the right hand side gets type cast to teh
type of the left,
It is not left up to the implementation to decide which way to cast
different types, nor is it dependant on the order. ECMA-262 it says:
11.9.1 The Equals Operator ( == )
The production EqualityExpression : EqualityExpression ==
RelationalExpression is evaluated as follows:
1. Evaluate EqualityExpression.
2. Call GetValue(Result(1)).
3. Evaluate RelationalExpression.
4. Call GetValue(Result(3)).
5. Perform the comparison Result(4) == Result(2). (Section 11.9.3.)
6. Return Result(5).
Section 11.9.3 says:
1. If Type(x) is different from Type(y), go to step 14.
[... since we are discussing different types ...]
14. If x is null and y is undefined, return true.
15. If x is undefined and y is null, return true.
16. If Type(x) is Number and Type(y) is String,
return the result of the comparison x == ToNumber(y).
17. If Type(x) is String and Type(y) is Number,
return the result of the comparison ToNumber(x) == y.
18. If Type(x) is Boolean, return the result of the comparison ToNumber
(x) == y.
19. If Type(y) is Boolean, return the result of the comparison x ==
ToNumber(y).
20. If Type(x) is either String or Number and Type(y) is Object,
return the result of the comparison x == ToPrimitive(y).
21. If Type(x) is Object and Type(y) is either String or Number,
return the result of the comparison ToPrimitive(x) == y.
22. Return false.
So there are quite explicit rules on how to do type conversions where
the comparison is between different types.
is how it works if the typing is loose. so whatever is
simplest should be on the left hand side.
That isn’t how it works - Henry has the answer.
so (probably wrong syntax) if ('5'> a) is slower than if(5> a) as the
former implies a string conversion.
From the spec you can see that if one is Number and the other String,
the string is converted to a number, always, regardless of the order
of the comparison.