Code like this:
var str = "Hello StackOverflow !";
alert(typeof str);
gives me string
as result. This means strings are not objects, then why do we have properties of a string str
like str.substring
, str.indexOf etc.?
Also when i set property to it as
str.property = "custom property is set";
and trying to get this alert(str.property)
, it gives me undefined
. Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…