3 ms·
It is type coercion. The runtime converts both operands to the same type before making the comparison (https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
by nfm 12y ago
It is type coercion. The runtime converts both operands to the same type before making the comparison (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...). This is also true of !, <, and friends.
Other operators in JavaScript may behave more intuitively than ==, but I don't think you can really make a good case for JavaScript's type coercion being 'unsurprising'.
- benaston 12y agoI suppose what I meant was that you point out that the coercive behavior of some operators is counter intuitive; ergo type coercion in JS is a mess. I dont think that follows because some operators behave in a coercive fashion more convenient than many other languages.