=== check | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

=== check

I don’t get the relevance of the === instead of == operator here. (rest params example 1 & 2) ?

1st Aug 2019, 5:32 AM
Shyla
Shyla - avatar
3 Answers
+ 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.
1st Aug 2019, 4:18 PM
Schindlabua
Schindlabua - avatar
+ 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)
1st Aug 2019, 6:11 AM
Schindlabua
Schindlabua - avatar
+ 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?
1st Aug 2019, 2:51 PM
Shyla
Shyla - avatar