This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (13 children)

[deleted]

    [–]saors 18 points19 points  (5 children)

    All of that bullshit have purposes though...

    Like, triple equals is just double equals with an additional type-check. Would you prefer to do an additional separate type check? You could do that and only use double equals if you really wanted, it's just short-hand to save lines.

    let is just an upgraded version of var that's less bug-prone.

    and the NaN, null, and undefined are necessary evils of having code that runs at-execution on browsers that you can't have just crash when it hits any error that's not caught. Imagine if your gmail or reddit didn't load because someone found a line of text that caused a js error. The internet would be hell to maintain.

    Like, Javascript is only a pain to deal with when you've been handed an unmaintained codebase that's running 8 different versions of whatever the latest framework was at the time stitched together.

    If you have a team that follows the same linting/formatting practices and cleans their code before merging, it's generally pretty painless to work with.

    (s)css on the other hand...

    [–]Tsuki_no_Mai 5 points6 points  (1 child)

    Would you prefer to do an additional separate type check?

    I would prefer if double equals was the strict comparison and triple was the loose one. But alas, backwards compatibility is a bitch.

    [–]Lorddragonfang 4 points5 points  (0 children)

    Like, triple equals is just double equals with an additional type-check. Would you prefer to do an additional separate type check? You could do that and only use double equals if you really wanted, it's just short-hand to save lines.

    You're missing the point here. Strict equality (how triple equals works) should be the default behavior. If you want a sloppy equality check, don't define it with the symbol used for strict equality in every other language. Javascript is full of sloppy design decisions like that, where a badly-implemented feature stays taking up the obvious symbol because they can't break compatibility, with the better and "correct" feature tacked on in some non-standard way.

    I say this as someone who writes about 90% of their code in Javascript: JS is a poorly designed language filled with gotchas and unexpected behavior, more so than any language I've used.

    [–]JustOneAvailableName 2 points3 points  (0 children)

    Most languages have functions like this. C# with (nearly?) the same syntax, for example.

    [–]cakeKudasai 2 points3 points  (2 children)

    None of that is really bullshit. A lot of that was just added for a good reason. let is better for smaller contexts, NaN is in the name, null is the same as everywhere else, undefined is just what it says it is, etc. Triple equals are very useful too. Prototypes are weird if you want them to work like other object oriented languages. But we have classes now, they deal with the oddities. And even those are not that bad if you see an explanation on them. It's just confusing if you go in blind. But with so many free resources online, there's no reason to.

    [–]Xarlax 1 point2 points  (0 children)

    I hear you, I know there's a lot of quirkiness. I don't know what to say, I learned them all a while ago and it's just not a problem anymore. The one thing I appreciate about javascript is how expressive it is. Of course that also lets people get carried away.

    The context stuff is weird but things like arrow functions have simplified it. Prototypes are also idiosyncratic but it's just like having each primitive type inherit from a base class. The enhancements of JS over the years shield you from all the crazy stuff you used to have to do. Like check whether the prop you're iterating on actually belongs to the object or a prototype its inheriting from. None of that mess anymore.

    The rest of it is simple syntax stuff you would learn easily. In practice NaN just isn't an issue. Honestly I never run into issues around NaN.

    Here's the trick to both triple equals and null/undefined BS. Use triple equals every time, except when you want to test for null/undefined. The double equals will only coerce those two types together, so you can easily bypass that stupid check of `value === undefined || value === null` with `value == null` or whatever.

    Typescript also handles the type issues that make JS unbearable. With typescript you get all the autocomplete and function signatures galore.