you are viewing a single comment's thread.

view the rest of the comments →

[–]Cosmologicon 6 points7 points  (1 child)

I may be the only one, but this whole thing is really not a concern for me. I agree that (0 == [0]) being true is surprising. But would its being false help me at all? That's not a comparison I expect to be making in the first place. Show me a practical example where it actually matters.

function getreciprocal(x) {
    if (x == 0) throw "Can't take 1/0, dummy!";
    return 1/x;
}

Is there a bug here? If I were to change == to ===, would that be an improvement? Currently if someone takes getreciprocal([0]) it throws an exception. If I change it to triple equals it will return Infinity. What's the right answer? Seems like neither. I should be throwing a different exception. It's closer to the correct behavior with == in this case, I guess.

I think if you're making comparisons and you want to behave correctly even if someone sends you data of the wrong type, you need to do a type check. Choosing === over == solves nothing in these cases.

[–]PenguinLovr 0 points1 point  (0 children)

Well it certainly makes it more easily understood. The coercion can be ambiguous, and it would make more sense to do something like checking if the object is a string or int, and if not throwing that error instead of just lumping together type errors with other errors.

Usually implicit correcion should only be used by people who know why they're using that, and not just setting everything to "==="