String Type
Description
The String type is the object representation for strings and is created using the String constructor as follows:
var stringObject = new String("hello world");
The methods of a String object are available on all string primitives.
valueOf(), toLocaleString(), and toString() from String type return the object's primitive string value.
Example
var stringValue = "hello world";
console.log(stringValue.toString());
console.log(stringValue.valueOf());
console.log(stringValue.toLocaleString());
The code above generates the following result.
Length
Each instance of String contains a property, length
, which indicates the number of
characters in the string. Consider the following example:
var stringValue = "hello world";
console.log(stringValue.length); //"11"
The code above generates the following result.