Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Primitives can be compared to see if their values are literally the
same. As logic would suggest, if you compare a variable containing the
numeric value 10 with another variable
containing the numeric value 10,
JavaScript will consider these equal because 10 is the same as 10 (i.e., 10 ===
10). The same, of course, would apply if you compare the
primitive string 'foo' to another
primitive string with a value of 'foo'.
The comparison would say that they are equal to each other based on their
value (i.e., 'foo' ===
'foo').
In the code below, I demonstrate the “equal by value” concept using primitive numbers, as well as contrast this with a complex number object.