+ 1
Why are objects with similar properties never equal?
[Objects and the strict equality===] E.g One = {num: 1, val: 1}; Once = {num: 1, val: 1}; So why is (One===Once) = false? Silly question but i just don't get it?
9 ответов
+ 4
Ash🔹💙🔹 there are broadly two types of data, either primitive type or reference type. Objects are stored in different memory location so the equality returns false whereas when you check for equality in primitives, it will check for their values.
This might help.
https://code.sololearn.com/WNMSKRh3BQxW/?ref=app
+ 3
because object is a complexe type and each one has its own adress in memory (pointer) so 2 objects with the same properties and same everything cannot be equal because they point to 2 different adress in memory. If you want an object "a" to be equal to object "b" you have to assign explicitly one object to another exemple : var a = b
+ 2
~ swim ~
How about variables
One = 1, Once = 1;
It's true when (One===Once)??????
Addresses are not compared in this case...why?😑
+ 2
Ash🔹💙🔹 It simply means that primitive types are checked for there values and object are checked for there memory location. Two primitive when have same value will return true but objects are created on the heap at different memory locations so they will return false.
+ 2
Because the manchine set in background different characteristics for each object
Because objects are the particular variables
+ 1
Avinesh I tried that.....does it mean primitive data types are stored in the same place....?
+ 1
~ swim ~ i and j are objects...= false ?
+ 1
I did check them.
brings us back to why objects !== .....but others can be ===
+ 1
Yes....!thanks though ~ swim ~