Yeah, is one of the things I don't like about JS. The typeof operator should be able to handle those cases. Or a new operator that returns a boolean would be nice.
Javascript lets you do anything wrong if you use == and not === though, I'm pretty sure the machine apocalypse is going to happen because someone types == instead of === at this point.
`0 === false` is maybe the only thing that I actually hate about javascript. Mutability, I understand and thus can deal with it. Scope, no biggie. But resolving a number to false, when all other numbers resolve to true? Inexplicable.
Usually it's awful. I wish JavaScript had if else expressions. Sometimes it can help to break up the lines with indents if you need a single expression:
FWIW, I almost always use ==. Very rarely, if ever, had any problems- probably I'm used to javascript enough to think in advance of the edge cases and use === when I feel it's necessary.
This however will not cause any errors, it just won't do anything:
> $("#nonexistent").html("");
These sort of do-nothing-but-don't-throw-an-error responses can encourage developers to be less careful about making sure elements exist as they are expected, etc.
It is trivially easy to avoid though, just use === instead of ==.
Most of the JavaScript wtf's are people getting confused by the implicit type conversions (like [] == ![]). If you ask for it, JavaScript will readily convert a string to a number or an object to a boolean. But if you don't like that, just don't rely on implicit conversions.
Also, this isn't a javascript problem; this is a problem of trying to be too clever and not understanding implicit conversion, which happens in many languages.
That one isn't specific to Javascript, though. If you can find a mainstream language that doesn't have any values that aren't equal to themselves, I'll give you a cookie.
(Going from memory of the last time I tried this challenge, since I can't get it to load at the moment.)
reply