I have two fiddles that apply the code below, the only difference being that one uses console.log while the other uses alert to show the value of the variable myString. One fiddle alerts the string ‘foo’ while the other logs foo like this foo {0="f", 1="o", 2="o"} What accounts for this difference?
var myString = new String('foo'); // produces a String() object
alert(myString);
console.logoutputs the actual content of the variable, which in this case is an object with properties.alerton the other hand casts everything to a primitive string first.