marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 795 forks source link

Chapter 4: Deep Comparison exercise clarifications #418

Closed fenekku closed 6 years ago

fenekku commented 6 years ago

Hi,

I really like the book, but I was confused by the following sentences when reading through the Deep Comparison exercise:

The == operator compares objects by identity

and later

To find out whether to compare two things by identity (use the === operator for that)

So, should I use == or === to compare by "identity"? I also ask because I don't know what "identity" means in this context. The only 2 times the term is used on this page is in those sentences. From chapter 1, === is used to compare precise equality (without type coercion). Is this identity?

Thanks for the great resource!

marijnh commented 6 years ago

The == operator compares objects by identity

Note the word objects. For objects, == and === do the same thing (compare by identity). For values in general, they don't.

fenekku commented 6 years ago

Thanks for bringing my attention to the use of objects there. I think "identity" was what really confused me though and so I made a pull request to actually use that word in the section about object identity. I also added in what you just said: == and === both compare by identity for objects. Hopefully that helps others? 😅

Thanks!

marijnh commented 6 years ago

I hope attached patch makes this paragraph easier to read

fenekku commented 6 years ago

Sorry about the delay. Yes this is clearer! I will close this issue. Thanks! :+1: