String() constructor

The String constructor is used to create a new String object. It performs type conversion when called as a function, rather than as a constructor, which is usually more useful.

Syntax

new String(thing)
String(thing)

Parameters

thing
Anything to be converted to a string.

Examples

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.

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
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

Legend

Full support  
Full support

See also