Every primitive type has a object wrapper type, just like how the data type number
has the object wrapper Number()
. As mentioned previously, primitive data types are passed by value while objects are passed by reference. In fact, since primitive data types can't hold properties, the JavaScript engine converts the primitive data type into its corresponding object type before calling the property of the string. You can use new String()
to explicitly create string object or use String(stringObject)
to create explicitly create a primitive string.