Why an object with the same key : value is not equal?

Tell us what’s happening:
Hello
I don’t understood why the result is not equal, except if comparing an object is not possible with the == operator
assert.notEqual({ value: 1 }, { value: 1 }, '== compares object references');

Can you give me more info ?

Thanks

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36

Challenge: Use the Double Equals to Assert Equality

Link to the challenge:

1 Like

This is exactly it. A Javascript variable holds one value. This works fine for primative data like numbers or boolean, but for complex stuff like objects and arrys, they are too big to fit into the variable. Instead, the variable holds the location in memory where the object is stored. In this case, two brand new objects won’t be stored in the same spot, so they won’t compare as equal.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.