+ 3
Why( var a = 7;, var b = 7; )a===b is false & (var c = a; )a===c is true. Having problem to understand JavaScript reference type
var a = { a : 7}; var b = { a : 7}; a==b // false a===b //false While var c = a; a==c //true a===c //true
9 Antworten
+ 5
despite the same content. a & b is 2 different object with different reference. so == and === here is not comparing the content of the object, but the object itself. thats why its false
meanwhile c=a. make c referencing the object of a. thus both have same reference.
try, c.a = 200;
you'll the value of a.a will also change, because c and a using same reference
+ 5
See your questions again :-
https://www.sololearn.com/discuss/2262944/?ref=app
+ 4
Hi
+ 4
== & === checks same objects not identical objects
+ 4
Here a ≠ b as they are 2 different objects while assigning a = c makes them same object. That is why it is true.
+ 3
Hi
+ 3
When dealing with objects, variables assignments are considered only a reference to the object (more like an arrow referring to a building) so .. build a building (an object) assign it to a variable pointing twords it .. in real life you can't say two different buildings are equal to each other, i.e: they aren't the same building.. because they're two different ones, right? This is why it's always false if you compare two diff objects in js with == , wvn if having the same properties within
But in case of assignments, eg: a = {a: 3};
C = a;
You simply making different pointers (arrows) to the same building.. so when you a == c.. it gives true .. because it's the same object
+ 2
Thanks
+ 2
Thanks to all