Consider the following codes:
var str = "abc";
str.foo = 123; // write - ignored
123
str.foo // read
undefined
Why do I get undefined? Shouldn't that property output 123
? What is the reason for it outputting undefined?
Since var str
is a string, why don't properties show up a second time?
Cant we add properties and methods to a string?