JavaScript String() Constructor

Beginner
5 min read
Updated: Nov 2026
4 examples
Constructor

Definition

The global String function converts a value to a string primitive when called without new. With new, it returns a String object wrapper. It is Baseline Widely available.

Pass the required arguments shown below. Prefer String(value) for coercion; avoid new String() unless you need an object wrapper.

Syntax

Create or coerce a string. Start with this line.

JavaScript
String(value) / new String(value)
CallWhat it does
String(value) / new String(value)Primary signature.

Built into JavaScript. Call String(...) (prefer without new) — no import required.

Library declarations
JavaScript
String(value) / new String(value)

Parameters

ParameterDescription
valueOptional. Value to coerce; omit → ""

Return Value

Return ValueDescription
*String primitive (typeof "string")

JavaScript Examples

Example 1 — String() vs new String()

Same text, different kinds of values.

JavaScript
const a = new String("Hello world");
const b = String("Hello world");

console.log(a === "Hello world");   // false
console.log(b === "Hello world");   // true
console.log(a instanceof String);   // true
console.log(b instanceof String);   // false
console.log(typeof a);              // "object"
console.log(typeof b);              // "string"
Try It Yourself

How It Works

  1. Object form. new String(...) wraps the text → typeof "object".
  2. Function form. String(...) returns the primitive "Hello world".
  3. Strict equality. Object vs primitive → a === "Hello world" is false; b matches.
  4. instanceof. Only the wrapper is an instance of String.

Example 2 — Convert Common Values

Everyday ToString results you will see often.

JavaScript
console.log(JSON.stringify(String()));          // ""
console.log(JSON.stringify(String(123)));       // "123"
console.log(JSON.stringify(String(true)));      // "true"
console.log(JSON.stringify(String(null)));      // "null"
console.log(JSON.stringify(String(undefined))); // "undefined"
console.log(JSON.stringify(String({})));        // "[object Object]"
Try It Yourself

How It Works

  1. Default. No argument → empty string "".
  2. Numbers & booleans. Become digit or "true" / "false" text.
  3. null & undefined. Become the words "null" and "undefined" (not empty).
  4. Plain objects. Default toString() → "[object Object]".

Example 3 — Stringify a Symbol with String()

String() is the explicit Symbol → text path (+ and templates throw).

JavaScript
const sym = Symbol("example");
console.log(String(sym));  // "Symbol(example)"

try {
  console.log("" + sym);
} catch (e) {
  console.log(e.name);     // TypeError
}

try {
  console.log("".concat(sym));
} catch (e) {
  console.log(e.name);     // TypeError
}
Try It Yourself

How It Works

  1. Explicit convert. String(sym) is allowed and returns "Symbol(example)".
  2. Concatenation refuses. "" + sym throws TypeError.
  3. concat refuses. "".concat(sym) also throws — use an explicit cast.
  4. Why it matters. String() is the only everyday path that stringifies Symbols without throwing.

Example 4 — Equality Trap with Objects

Why new String surprises beginners with ===.

JavaScript
const wrapped = new String("hi");
const primitive = String("hi");

console.log(wrapped === "hi");           // false
console.log(primitive === "hi");         // true
console.log(wrapped.valueOf() === "hi"); // true
console.log(String(wrapped) === "hi");   // true
Try It Yourself

How It Works

  1. No auto-unbox for ===. A String object is not strictly equal to "hi".
  2. Primitives compare cleanly. String("hi") === "hi" is true.
  3. Escape hatch. .valueOf() or String(wrapped) extracts the primitive.
  4. Best fix. Do not create String objects — stay with literals and String(x).

Browser & Runtime Support

The String constructor is Baseline Widely available and supported in every modern browser and Node.js.

✓ Baseline · Widely available

String() constructor

Safe for production everywhere. Prefer String(value) for conversion; avoid new String().

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
String() Excellent

Bottom line: Use String(value) to coerce to a primitive. Avoid new String(). Use String(sym) when you must stringify a Symbol.

Frequently Asked Questions

String is a built-in global. Call String(value) without new to coerce value to a string primitive. Call new String(value) to wrap that text in a String object — rarely needed in everyday code.
String("hi") returns the primitive "hi" (typeof "string"). new String("hi") returns a String object (typeof "object"). Prefer the function form; MDN warns you should rarely use String as a constructor.
Strict equality compares type and value. A String object and a string primitive are different types even when their text matches. Prefer String(value) or string literals so you stay with primitives.
Yes. String(Symbol("x")) returns "Symbol(x)". Template literals, + concatenation, and "".concat(symbol) throw TypeError, so String() is the safe explicit path.
String() with no argument returns an empty string "". String(undefined) returns "undefined". String(null) returns "null". Objects use their toString() result (often "[object Object]").
String has been part of JavaScript since early editions. It is Baseline Widely available in every modern browser and Node.js.

Next: String length

Learn how length counts UTF-16 code units, empty checks, and emoji pitfalls.

String length →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful