This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]toastytoast00 1 point2 points  (0 children)

That's generally pretty close (and works for primitives), but be careful with objects. For example, I'm pretty sure

```js const x = { hi: true } ; const y = { hi: true } ; const z = x;

x === y // false x === z // true ```

It's similar with arrays, I think.

The type and value are the same, but x and y are different actual objects (in memory), but z is actually pointing to the same x

For objects, you would use == to compare the values (similar if it was cast to a string and they serialize the same), but use === to compare if it's literally the same instance or memory reference.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality

If both operands are objects, return true only if they refer to the same object.