ganqqwerty / 123-Essential-JavaScript-Interview-Questions

JavaScript interview Questions
BSD 3-Clause "New" or "Revised" License
5.01k stars 1.18k forks source link

Question 31 #79

Open Enzaik opened 5 years ago

Enzaik commented 5 years ago

Both compares return false. This is because in JavaScript we pass non primitive data types by reference. So, say: {id:1} == {id:1} // returns false even though is shallow compare, we are not comparing here two objects values, but 2 references, which are different.

ganqqwerty commented 5 years ago

you are totally right, this question is misleading. Will remove it.

Enzaik commented 5 years ago

Anyway, the guide is very good 😊 congrats!

akashpjames commented 4 years ago

@ganqqwerty I came here to create this issue but found there is already a ticket for it. Is this question relevant? Because if we need to shallow copy, can't we just assign it? Eg: var object1 = {a: 1}; var object2 = object1;