Numbers and Boolean values (true and false) are copied, passed, and compared by value.
Objects, arrays, and functions are copied, passed, and compared by reference.
When comparing by reference, the two variables must refer to exactly the same entity for the comparison to succeed. For example, two distinct Arrayobjects will always compare as unequal, even if they contain the same elements. One of the variables must be a reference to the other one for the comparison to succeed. To check if two Arrays hold the same elements, compare the results of the toString() method.
var a=[]; var b=[]; console.log(a==b);//output:false
Last, strings are copied and passed by reference, but are compared by value. Note that if you have two String objects (created with newString("something")), they are compared by reference, but if one or both of the values is a string value, they are compared by value.
var a=""; var b=""; console.log(a==b);//output:true; var a1=new String(""); var b1=new String(""); console.log(a1==b1);//output:false;
It's very funny:
console.log(a==a1);//output:true; console.log(a==b1);//output:true; console.log(a1==b1);//output:false;
浙公网安备 33010602011771号