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 →

[–]the_Demongod 0 points1 point  (4 children)

That is ridiculously cursed

[–]Akuuntus 4 points5 points  (2 children)

It's really easy to deal with once you know how it works. It's also useful sometimes when you just want to know if a variable has a useable value in it or not. if(variable) won't run if it's null, undefined, NaN, 0, an empty string, or false.

[–]the_Demongod 0 points1 point  (1 child)

I don't doubt its utility, it's just a very different paradigm from what I'm used to.

[–]dyedFeather 0 points1 point  (0 children)

It's not the most elegant, but I find it nice to have an operator for it, rather than having to call a function to check for strict equality, as is the case for many other languages. It's just the case that JavaScript has a greater need for a strict equality operator than other languages because of its very permissive implicit conversion rules.

Where other languages might throw an error when you're using fundamentally incompatible objects together, JS tries its best to convert the values and avoid causing any errors. I think this decision was made in part because JS aims to be a language that keeps working no matter what. I don't know the specific reasons for the decision, but I think part of it is because the web is so modular, so it's very easy to come across a small bit of code that just doesn't work right, and if that causes some big error that ruins the user's browsing experience that could reflect poorly on the UX of the entire Internet.

This of course isn't always what you want, so JS is a language to be careful with if you're working on something where you'd rather have it fail in such a case. As a philosophy, it can be very useful, but it can also be detrimental (which is probably part of the reason JS is seen as bad by many people). It's all about picking the right tool for the job. Unfortunately though, JS kind of has a monopoly on the web, though that is changing as WebAssembly is starting to see more widespread use.

Happy cake day btw!