Strings are not object then why do they have properties?

前端 未结 5 2023
孤城傲影
孤城傲影 2020-12-19 12:42

Code like this:

var str = \"Hello StackOverflow !\";
alert(typeof str);

gives me string as result. This means strings are not

5条回答
  •  -上瘾入骨i
    2020-12-19 12:57

    Strings are pure objects: http://www.ecma-international.org/ecma-262/5.1/#sec-15.5

    So the question is, what does the typeof operator. It simply acts according to its ECMA specification:

    http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3

提交回复
热议问题