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

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -