DEV Community

loading...

Discussion on: JavaScript Equality Checks

Collapse
andreybarkov profile image
Andrey Barkov

Can it be used to compare two different objects with same properties?

Collapse
ronakjethwa profile image
Ronak Jethwa Author • Edited

Yes. Two different Objects with same properties are still two different objects with different memory references, so that would still return false with Object.is().

let user1 = {name: 'John', age:29};
let user2 = {name: 'John', age:29};
Object.is(user1,user2); // false

Although, this will be different.

let user1 = {name: 'John', age:29};
let user2 = user1
Object.is(user1,user2); // true