By Paulo Diniz
The Distinction Between String Primitives and String Objects
String primitives and String objects also give different results when using eval(). Primitives passed to eval are treated as source code; String objects are treated as all other objects are, by returning the object. For example:
For these reasons, code may break when it encounters String objects when it expects a primitive string instead. Generally authors need not worry about the distinction.
A String object can always be converted to its primitive counterpart with the valueOf() method.
console.log(eval(s2.valueOf())); // returns the number 4
As I’ve explained in my post on arrays, the primitive C array data type consist of a contiguous memory location on disk and cannot be modified once allocated. The reason all this becomes important is the following:
All operations on Strings (except as otherwise stated) treat them as sequences of undifferentiated 16-bit unsigned integers; they do not ensure the resulting String is in normalised form, nor do they ensure language-sensitive results (source).
Thus, only String function that should be used to normalize a string value is
String.prototype.normalize. Finally, when using other String functions be aware that this is not being done for you and might result in unexpected errors when dealing with different data types.