Javascript - String String Type


The String type is the object representation for strings and is created using the String constructor:

var stringObject = new String("hello world");

The methods of a String object are available on all string primitives.

valueOf(), toLocaleString(), and toString() of string object return the object's primitive string value.

Each instance of String contains a property, length, which indicates the number of characters in the string.


var stringValue = "hello world";
console.log(stringValue.length);   //"11"


This example outputs "11", the number of characters in "hello world".