+ 1
Strings equality in JavaScript
Why "string" === "string" is false in JavaScript.
3 odpowiedzi
+ 4
// Test the code again
console.log("string" === "string") // true
// Do you mean new String("string")?
console.log(new String("string") === new String("string")) // false, different objects
+ 4
a and b are different objects. they are different instances of String().
=== compares for identity, not the content of the String objects.
+ 2
var a = new String("hello");
var b = new String("hello");
if(a === b) {
alert("a");
} else {
alert("b");
}
Why this is resulting in "b"?