Skip to main content
Version: 1.3.0

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.

Syntax

new String(thing)
String(thing)

Note: String() can be called with or without new, but with different effects. See Return value.

Parameters

  • thing
    • : Anything to be converted to a string.

Return value

When String is called as a constructor (with new), it creates a String object, which is not a primitive.

When String is called as a function, it coerces the parameter to a string primitive. Symbol values would be converted to "Symbol(description)", where description is the description of the Symbol, instead of throwing.

Warning: You should rarely find yourself using String as a constructor.