3 ms·
Why are you being a dick? He explained the difference accurately - JS compares objects as individual objects. Arrays are objects. The other languages you cited
by artursapek 13y ago
Why are you being a dick? He explained the difference accurately - JS compares objects as individual objects. Arrays are objects. The other languages you cited do not work that way.
Here's another example:
4 == 4 // true
a = new Number(4);
b = new Number(4);
a == b // false
a == a // true
a.valueOf() // 4
b.valueOf() // 4
a.valueOf() == b.valueOf() // true
And if this isn't clear yet:
a = {}
b = {}
a == a // true
a == b // false
- rdtsc 13y agoRather his tone of "Why would it be true?" sounded dick-ish. As in "How could possibly one consider [1] == [1] be true, are you crazy? It should obviously be false". So I gave a couple of examples from other dynamic languages where the the sane behavior is "obvious". I am not being a dick I am saying the language is broken. Explaining the historical context or the internal implementation of it doesn't make it unbroken. Like one can explain why COBOL uses this construct or that and how it came to be, doesn't make COBOL better or more appealing. One of course might not have a choice and be stuck using it but lying to oneself about how awesome it is, is not necessary. > The other languages you cited do not work that way. The don't, and I like how they work better. Now whether one has a choice to use or not use JS is a different topic. Usually there is no choice on the client side. But somehow extolling Javascript typing rules as being sane, making sense, or as someone below put it "brilliant" is a bit silly.
- artursapek 13y agoNo, he didn't ask it like that at all. You're putting words in his mouth instead of reading the sentence in the context of the two sentences that followed it, which made it a completely reasonable question.