I have seen many explanations of javascript identity equal operator ===
, but seems they are not quite accurate as what we understand of identity equality in other languages such as Java.
Seems for base types (such as number, string), ===
return true indicates if two variables are with the same type and value. But not necessarily the same identity (references to the same object). But for array and map, it does. Here are some examples that cause confusion for me:
s1 = 'a' + '1'
s2 = 'a' + '1'
s1 === s2 // true, even they actually reference two different
objects in memory which suppose to be different identities.
a1 = [1,2]
a2 = [1,2]
a1 === a2 // false, as they reference two different objects in memory, even their values are the same.
Could somebody confirm my understanding is right? Also is there a real identity equality check for strings in Javascript. i.e. s1 === s2
should return false
in the above example?