Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

String — explicit conversion to text

String(value) converts a value to a primitive string. Calling it without an argument returns an empty string. If conversion succeeds, new String(value) creates a wrapper object rather than a primitive value.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

String(value)
String()
new String(value)

String is a built-in ECMAScript function, not a browser API. Calling String(value) returns a primitive string if conversion succeeds. The String type represents immutable sequences of 16-bit code units, normally interpreted as UTF-16; one visible letter or other character does not necessarily correspond to one code unit.

Omitting the argument differs from passing undefined: String() returns "", but String(undefined) returns "undefined". Similarly, String(null) produces "null", and String(42) produces "42". A direct Symbol argument receives special handling: String(Symbol("tag")) returns "Symbol(tag)".

This special handling applies only when called without new: new String(Symbol("tag")) throws a TypeError instead of creating a wrapper object. If conversion succeeds, new String(value) creates a wrapper object. Consequently, typeof String("hello") produces "string", whereas typeof new String("hello") produces "object". Comparing these values with strict equality, ===, produces false. For ordinary text conversion, use String(value) without new.

Converting an object can invoke its own conversion mechanisms, such as [Symbol.toPrimitive] or toString, and can throw an exception. String(value) is neither JSON serialization nor a way to safely display arbitrary untrusted objects without executing their code.

Examples

console.log(JSON.stringify([String(), String(undefined), String(null), String(42)]));
console.log(String(Symbol("tag")));
const text = String("hello");
const wrapped = new String("hello");
console.log(typeof text, typeof wrapped);
console.log(text === wrapped);

Result

["","undefined","null","42"]
Symbol(tag)
string object
false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources