Is String a Primitive type or Object in Javascript? -


is string primitive type or object in javascript? source says undefined, null, boolean, number , string primitive types in javascript. says string object too. i'm confused. can please explain?

thank in advance ;-)

both.

there string object , there string literals.

you can call string method on literal , can call string method on string object.

the major difference string object generates new object new string("foo") !== new string("foo")

that , string object type "object" , not "string"

how check both?

if(typeof(s) == "string" || s instanceof string){   //s string (literal or object) } 

credits @triynko snippet in comments


Comments

Popular posts from this blog

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -

Python __call__ special method practical example -