js stringConstructor type 1

js stringConstructor type

var str = "foo";
str.prop = "bar";
alert(str.prop); // undefined

var str = new String("foo");
str.prop = "bar";
alert(str.prop); // "bar"

Here is what the above code is Doing:
1. The first alert displays undefined because the string literal “foo” is not an object.
2. The second alert displays “bar” because the String object “foo” is an object.

Similar Posts