Why does javascript treat "xy" == new String("xy") as true, but "xy" === new String("xy") as false?.
I have read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators, but am still confused
Why does javascript treat "xy" == new String("xy") as true, but "xy" === new String("xy") as false?.
I have read https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators, but am still confused
typeof "xy"
is "string"
typeof new String("xy")
is "object"
=== compares both value and type
== converts the types and then compares just the values
the == operator just compares the values, === compares values and types. So type of "xy" is string and type of new String() is object. That's why you see the difference between those two comparisons