|
|
|
|
|
by nolok
3250 days ago
|
|
> Is this incorrect? Yes it is. The reason for the deep equality check is not so much that you want the check on type, but because this way you avoid the entire giant class of errors caused by type coercion, just like in PHP. Think things like: function check_user_id(user_id) { return user_id == 1; }
check_user_id('1 error detected');
It's obvious when you see the exemples, and is usually a bug somewhere due to a missing check, but in language such as this it can often causes deep errors yet stay unseen for months.There is a reason why strict type hinting has become a most-wanted (and now beloved) feature of PHP, and of JS through language such as TypeScript: most of the time, you don't really care like you said if it's '1' or 1, but because it's supposed to be a number anyway it makes no sense to not force it to be one or error out. In other words, it's better to trade "I don't want deep equality check most of the time" with "I don't want lax equality most of time". |
|