Why does the creation of a string object not return true when compared strictly to a primitive string value?
var obj = new String('0');
var str = '0';
console.log(obj == str); //returns true
console.log(obj === str); //returns false
As obj
type is object
where str
is string
, Hence obj === str
is false
.
var obj = new String('0');
var str = '0';
console.log(typeof obj);
console.log(typeof str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With