I have read Which equals operator (== vs ===) should be used in JavaScript comparisons?, but it didn't help me because it doesn't say whether objects can be reused by the JS virtual machine.
In Javascript, is it guaranteed that two objects created successively (and of course not by assigning one to another) have a different reference?
Consider the following snippet:
let a = {};
let b = {}; // b can be created at any time after a is created
let areEqual = a === b; // comparison can be done at any time after b is created
Is it guaranteed that areEqual
is false
? That some processor optimization won't make b
re-use a
's reference?
Yes! Triple Equals is a combination of Value & Type. When you compare non-primitive variables in javascript what you are really comparing is their reference id. In other words, in your example a
will never equal b
, nor will it with any amount of processor optimization.
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