+ 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?

1st May 2020, 9:15 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
13 Respostas
+ 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
1st May 2020, 9:56 PM
Avinesh
Avinesh - avatar
+ 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
2nd May 2020, 11:41 AM
Maher Najar
Maher Najar - avatar
+ 2
~ swim ~ How about variables One = 1, Once = 1; It's true when (One===Once)?????? Addresses are not compared in this case...why?😑
1st May 2020, 9:35 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 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.
2nd May 2020, 9:55 AM
Avinesh
Avinesh - avatar
+ 2
Because the manchine set in background different characteristics for each object Because objects are the particular variables
3rd May 2020, 7:44 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 1
Avinesh I tried that.....does it mean primitive data types are stored in the same place....?
1st May 2020, 10:25 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 1
~ swim ~ i and j are objects...= false ?
1st May 2020, 10:32 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 1
I did check them. brings us back to why objects !== .....but others can be ===
1st May 2020, 11:00 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar
+ 1
Yes....!thanks though ~ swim ~
1st May 2020, 11:13 PM
asɥɐ🔹ʞɐɹnnƃı
asɥɐ🔹ʞɐɹnnƃı - avatar