String() constructor

The String constructor is used to create a new String object. When called instead as a function, it performs type conversion to a primitive string, which is usually more useful.


new String(thing)


Anything to be converted to a string.


String constructor and String function

String function and String constructor produce different results:

typeof String('Hello world'); // string
typeof new String('Hello world'); // object

Here, the function produces a string (the primitive type) as promised. However, the constructor produces an instance of the type String (an object wrapper) and that's why you rarely want to use the String constructor at all.


ECMAScript (ECMA-262)
The definition of 'String constructor' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
String() constructorChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100


Full support  
Full support

See also