I run the following code in a browser console (FireFox and Chromium):
console.log('v' > 5);
console.log('v' < 5);
'v' < 5
'v' > 5
The coercion is in the other direction.
'v' is coerced to number, yielding
NaN, which will make any comparison with another number return
See "What is the rationale for all comparisons returning false for IEEE754 NaN values?" on the behaviour of
From the EcmaScript specification:
In 12.9.3 Runtime Semantics: Evaluation the evaluation of both
> operators is specified, with this important step:
- Let r be the result of performing Abstract Relational Comparison rval < lval with LeftFirst equal to
- If r is
false. Otherwise, return r.
The 7.2.11 Abstract Relational Comparison starts out with:
The comparison x < y, where x and y are values, produces
undefined(which indicates that at least one operand is
NB: Note that
undefined will lead to a
false in the final evaluation, as stated in above quoted step 8 of section 12.9.3.
It is then required that after the primitive values have been taken from the operands, and they are not found to be both strings, they should be coerced to Number:
- If both px and py are Strings, then
a. Let nx be ToNumber(px).
c. Let ny be ToNumber(py).