3 ms·
Generally type coercion seems like a bad idea in most languages
by VMG 14y ago
Generally type coercion seems like a bad idea in most languages
- chris_wot 14y agoWhich is why you can use === to bypass type coercion when dong an equality test.
- lucian1900 14y agoBut === is the other equals, not the equals. Also, that only helps in boolean contexts, not with any function calls.
- chris_wot 14y agoAlso, that only helps in boolean contexts, not with any function calls. Could you clarify?
- lucian1900 14y ago'1' === 1 is false, because === is strict. But there's no strict equivalent of + or -, so '1' + 1 is '11', but '1' - 1 is 0. The same holds for parseInt('Ambulance', 16) and parseInt('A', 16), which are both 10.