Why {} == {} and {} === {} is false in javascript?
{} == {} // false
{} === {} // false
Each object, each {} is distinct. Same applies to arrays, too. Show activity on this post. 2) it does not make any difference whether you use == or === for comparing objects, because comparing them always returns false.
In JavaScript, objects are a reference type. Two distinct objects are never equal, even if they have the same properties. Only comparing the same object reference with itself yields true.
google doesn't have value (undefined, null) then use {} . It is a way of assigning a default value to a variable in JavaScript. Follow this answer to receive notifications.
Double equals, == , performs an amount of type coercion on values before attempting to check for equality. So arr == arr returns true as you'd expect as what you are actually checking is if [] == [] and both sides of the equation are of the same type.
javascript compares objects by identity, not value. Each object, each {}
is distinct.
Same applies to arrays, too.
1) The reason for this is that internally JavaScript actually has two different approaches for testing equality. Primitives like strings and numbers are compared by their value, while objects like arrays, dates, and plain objects are compared by their reference. That comparison by reference basically checks to see if the objects given refer to the same location in memory.so
{} == {} is false
2) it does not make any difference whether you use == or === for comparing objects, because comparing them always returns false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With