javascript - confusion with instanceof Array and String -
this question has answer here:
- why instanceof return false literals? 10 answers
i read instanceof answer,but have question when code
["a","b"] instanceof array
why reutrns true same
new array("a","b") instanceof array
while
"a" instanceof string
returns false not same
new string("ab") instanceof string
? appreciate answers , help!
for strings, have both
- primitive strings (the ones manipulate of times, , literals)
- and instances of
string
class.
and they're not same.
here's what mdn says on distinction between both.
another way see difference, mdn doesn't point, can add properties on objects :
var = "a"; a.b = 3; // doesn't add property wrapped copy console.log(a.b); // logs undefined = new string("a"); a.b = 3; console.log(a.b); // logs 3
(remember of times, should use primitive strings)
for arrays, have arrays, there nothing primitive array.
Comments
Post a Comment