No, string primitives have no methods. As with numerical primitives, the JavaScript runtime will push them to full-blown String objects when invoking constructs such as:
var space = "hello there".indexOf(" ");
In some languages (well, in particular, in Java, but I think this term is generally accepted), he said that the language “puts” primitives in its object wrappers when necessary. With numbers, this is a little more complicated due to the vagaries of the grammar of the marker; you can't just say
var foo = 27.toLocaleString();
because "." will not be interpreted as you need; However:
var foo = (27).toLocaleString();
works great. With string primitives —— and boolean, for that matter; grammar is not ambiguous, therefore, for example:
var foo = true.toString();
will work.
source share