javascript - confusion with instanceof Array and String -


this question has answer here:

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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -