In the following code the function is used Boolean to return a value. If you do a strict comparison of the result of two functions that return the same value the result is true, but if you are comparing two objects created using new Boolean the result is false.
var salidas = [ Boolean(true), Boolean(true) === Boolean(true), new Boolean(true) === new Boolean(true), ] console.log(salidas.join('\n'));
Why is it that when you compare two objects that have been created using the same code the result is false? How do you explain this to the ECMAScript 2016?
I guess that the answer is going by the following
Boolean(true)returns a data primitive of type boolean with value
new Bolean(true)returns an object that inherits the properties of the object
- Each time it is called
new Bolean(true)you have objects that have the same structure inherited from the object Boolean, not to be confused with the primitive Boolean.
- By inheritance structure I refer to both objects will have properties at the least of name, however, there is something that makes them different to the two objects and hence a strict comparison of these returns
What is it that makes it different to the two objects that inherit properties from the same object?
Apparently here the key concepts to differentiate are equality and identity
By equality, we have to understand that two things are equal when these have the same values and when it comes to objects have the same properties, and these with the same values
By identity, we have to understand that two things are identical, that is to say that they are not two things, but it is the same thing, both are one and only one thing.
Two instances of an object are not identical, even if they were created virtually at the same time, are two different things.
In the ECMAScript does not I found talk of it earlier, but yes, to some extent, Equality comparisons and sameness
Note: the link above points to the English version because the Spanish language does not include references to the most recent versions of ECMAScript being the English if it does.