String

String – Creates a wrapper object to allow you to work with strings.

Description

new String([string string])

Parameters

Name Description Type Default Optional
string string Yes

Examples

Example #1 – string example

Three ways of creating a new string.

var txt = new String('string'); // Created a new string object. console.log(txt);
var txt = 'string'; // Create a new string primitive. console.log(txt); // string
var expression = new Number(1000); var txt = String(expression); // Used to convert a non-string to a string primitive. console.log(txt); // Logs 1000 as a string primitive.

See also

External references