Because JavaScript has both primitive and object versions of numbers and strings (and logical values). new Number and new String create object versions, and when you use == with object references, you compare object references, not values.
new String(x) and String(x) are fundamentally different things (and this is true with Number ). Using the new operator, you create an object. Without the new operator, you are executing a coercion type โ for example, String(2) gives you "2" and Number("2") gives you 2 .
source share