+ 3
=== check
I don’t get the relevance of the === instead of == operator here. (rest params example 1 & 2) ?
3 Antworten
+ 2
I mean you are not wrong but it is backwards. Reference equality is the "simpler" of the equality checks, == does a lot more behind the scenes, like convert between types.
So your thinking shoud be "reference equality is all that is needed/good enough, value type equality is not required".
I don't know why == isn't deprecated, I will ask around and get back to you about that.
However, check this out: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness
It's a great read. The main problem is that == requires you to memorize a big table of what converts to what at all times. And nobody does and so you get bugs and that's why it's broken.
undefined == null can be useful though.
+ 3
Just know that == is broken and === was added to the language to fix it. There is no reason to use == ever. Best pretend it doesn't exist, === should be what you use 100% of the time.
(For example 1 == "1" which is just silly and leads to bugs)
+ 1
Specifically how == is broken would be good to know. Value type equality check is all that is needed/good enough here, and reference equality check is not required here. After all == also yields the same result in this case(s).
Also, if == is so broken, wouldn’t they have deprecated that operator?