Of the five primitive JavaScript data types (string, number, boolean, null and undefined), the first three have associated constructors:
new String("Hello!")
new Number(40)
new Boolean(true)
The constructed objects are wrappers for the object literals. In particular, new String("Hello!") === "Hello!" evaluates to false.
Are there a similar constructors for the null and undefined primitive data types that produce object wrappers different from the corresponding object literal?
No, there are not, and it wouldn't make sense considering the "values" they represent.
Ignore the fact that typeof null === 'object'
According to MDN:
JavaScript automatically converts primitives and String objects, so that it's
possible to use String object methods for primitive strings.
The interpreter just does some magical auto-wrapping of primitive in classes if you call a method that affects the primitive, like charAt.
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