new String("...")
returns a string object .
"..."
returns the string primitive .
Some differences are as follows:
new String("foo") === new String("foo")
- false
; equality rules for object references"foo" === "foo"
- true
; string equality rules
and
new String("foo") instanceof Object
- true
; this is an object derived from Object
"foo" instanceof Object
- false
; it is not an object, but a primitive value
In most cases, you just need a primitive value because of these "quirks." Note that string objects are automatically converted to primitive strings automatically when they are added, by calling String.prototype
functions on them, etc.
Additional information in the specifications .
pimvdb
source share