Code like this:
var str = \"Hello StackOverflow !\";
alert(typeof str);
gives me string as result. This means strings are not
A string like "Hello" is not an object in JavaScript, but when used in an expression like
"Hello".indexOf(2)
A new object derived from the constructor function String is produced wrapping the string "Hello". And indexOf is a property of String.prototype so things work as expected, even though there is a lot of magic going on.
In the following case
> var s = "xyz"; s.prop = 1; console.log(s.prop);
undefined
The reason you see undefined is that:
s is given a value which is a primitive strings.prop = 1 and property named prop is assigned to a new, anonymous wrapper object.s. That is not the same wrapper object as in the second statement, and it does not have a prop property, so undefined is produced when asking for its value according to the basic JavaScript rules.