JavaScript String Constructor

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Global constructor

What You’ll Learn

The global String function creates text in JavaScript—either as lightweight primitives or as wrapper objects (same API as MDN String() constructor). Call it as a function for conversion; avoid new String() in everyday code. This tutorial covers coercion rules, Symbol stringifying, equality traps, five examples, and try-it labs.

01

Convert

String(42)

02

Literal

"hello"

03

Object

new String()

04

Symbol

String(sym)

05

Prefer

Primitives

06

Baseline

Everywhere

Introduction

Almost every string you write in JavaScript is a primitive typeof "string" value — for example "Hello", `Hi ${name}`, or String(99).

Calling new String(value) instead wraps that text in a String object. Objects are heavier, fail some === checks against primitives, and are almost never what you want. MDN’s guidance is clear: you should rarely use String as a constructor.

💡
Function vs constructor

Use String(value) (no new) to coerce to a string primitive. Use a literal like "hello" when you already know the text. Reach for new String() only if you truly need a String object.

Continue with length, toString(), and the String methods hub after you understand conversion.

Understanding the String Constructor

When String runs as a function, it applies ToString-style coercion: numbers and booleans become text, null becomes "null", undefined becomes "undefined", and objects use toString(). Symbols convert to "Symbol(description)" instead of throwing — that special case is unique to String().

  • String(value) → string primitive.
  • new String(value) → String object (avoid).
  • No argument: String() returns "".
  • Symbols: only String(sym) stringifies safely without throwing.

📝 Syntax

Two forms of the global String function (from MDN):

JavaScript
String(thing)        // returns a string primitive
new String(thing)    // returns a String object

Parameters

  • thing (optional) — anything to convert or wrap. If omitted, the function returns ""; with new you get a String object wrapping "".

Return value

  • String(thing)thing coerced to a string primitive. Symbols become "Symbol(description)" instead of throwing. Missing argument → "".
  • new String(thing) — a String object wrapping that coerced text (not a primitive).

Common patterns

JavaScript
String(123);            // "123"
String(true);           // "true"
String(null);           // "null"
String(undefined);      // "undefined"
String();               // ""
String(Symbol("x"));    // "Symbol(x)"  — safe path

const a = new String("Hello world");
const b = String("Hello world");
a === "Hello world";    // false
b === "Hello world";    // true
typeof a;               // "object"
typeof b;               // "string"

⚡ Quick Reference

GoalCode
Create text (preferred)"hello" or `hi ${n}`
Convert any valueString(value)
String object (avoid)new String("hi")
Check primitivetypeof s === "string"
Check String objects instanceof String
Symbol → textString(sym)
Object vs primitive ===false even if text matches

🔍 At a Glance

Four facts to remember about the String constructor.

Convert
String(x)

Returns primitive

Object
new String(x)

Rare — avoid

No args
""

String() → empty

Symbol
String(sym)

Safe stringify

📋 Literal vs String() vs new String()

Literal "hi"String("hi")new String("hi")
typeof"string""string""object"
instanceof Stringfalsefalsetrue
=== "hi"truetruefalse
Best for?Known textConversionAlmost never

Examples Gallery

Examples follow MDN String() constructor patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

See how String() and new String() differ at runtime.

Example 1 — String() vs new String()

Same text, different kinds of values (MDN String constructor and String function).

JavaScript
const a = new String("Hello world"); // a === "Hello world" is false
const b = String("Hello world");     // b === "Hello world" is true

a instanceof String;  // true
b instanceof String;  // false
typeof a;             // "object"
typeof b;             // "string"
Try It Yourself

How It Works

String("Hello world") coerces to the primitive text. new String("Hello world") builds a wrapper object. Prefer the function form.

📈 Practical Patterns

Everyday coercion, Symbol conversion, and equality traps.

Example 2 — Convert Common Values

Useful ToString results you will see every day.

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

How It Works

No argument means empty text. null and undefined become the words "null" / "undefined" — not empty strings. Plain objects use the default toString() tag.

Example 3 — Stringify a Symbol with String()

MDN: String() is the explicit Symbol → string path.

JavaScript
const sym = Symbol("example");

String(sym);  // "Symbol(example)"
Try It Yourself

How It Works

Because you called String() on purpose, JavaScript allows the conversion and returns "Symbol(description)".

Example 4 — Why Other Conversions Throw

Implicit string conversion refuses Symbols — only String() is safe.

JavaScript
const sym = Symbol("example");

String(sym);       // "Symbol(example)"

// "" + sym;       // TypeError
// `${sym}`;       // TypeError
// "".concat(sym); // TypeError
Try It Yourself

How It Works

Template literals and + try to convert silently and throw to protect unique Symbol identity. Use String(sym) when you really want text.

Example 5 — Equality Trap with Objects

Why new String surprises beginners with ===.

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

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

How It Works

=== does not unbox for you. If you somehow have a String object, call .valueOf() / toString() or pass it through String() again — or better, never create the object.

🚀 Common Use Cases

  • Normalize mixed types — turn numbers, booleans, or nullish values into text for display or logging.
  • Form / API outputString(id) before concatenating into URLs or messages.
  • Safe Symbol labelsString(sym) when debugging keys that must become text.
  • Default empty textString() when missing input should mean "".
  • Teaching types — show why new String breaks ===.
  • Not a substitute for formatting — prefer template literals for readable multi-part strings.

🧠 How String(value) Works

1

Receive a value

Number, boolean, Symbol, null, undefined, object, or another string.

Input
2

Apply ToString rules

Coerce using ECMAScript conversion (Symbols allowed here).

Coerce
3

Return primitive or object

Function call → primitive. new → String object.

Result
4

Use string methods next

Call trim, slice, includes, and more on the result.

📝 Notes

  • Prefer literals and String(value) — not new String().
  • String(null) is "null"; empty string only comes from String() or String("").
  • Template literals and + throw on Symbols — String() does not.
  • String objects still work with methods via auto-unboxing, but stay with primitives.
  • Related: length, toString(), valueOf().
  • Instance methods live under the String methods hub.

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 need Symbol text without TypeError.

Conclusion

The String constructor is your conversion tool: String(value) returns a string primitive, while new String(value) returns a rarely useful object wrapper.

Continue with length, prototype, toString(), or the String methods hub.

💡 Best Practices

✅ Do

  • Use string literals / templates for known text
  • Call String(value) for conversion
  • Use String(sym) when Symbols must become text
  • Check typeof s === "string" for primitives
  • Prefer template literals for readable multi-part strings

❌ Don’t

  • Use new String() in application code
  • Compare String objects to primitives with === and expect true
  • Assume "" + sym or `${sym}` will work
  • Confuse String(null) ("null") with an empty string
  • Build HTML with string wrappers — use DOM APIs instead

Key Takeaways

Knowledge Unlocked

Five things to remember about the String constructor

Convert with String(); avoid new String().

5
Core concepts
📝 02

Kind

primitive

Result
03

new

avoid

Trap
🟢 04

Symbol

String(sym)

Safe
05

===

type matters

Equality

❓ Frequently Asked Questions

String is a built-in global function. 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"). Primitives are lighter and what you should use by default. 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.
Did you know?

JavaScript auto-boxes string primitives when you call methods like "hi".toUpperCase(). You get the String API without ever writing new String("hi").

Explore String Methods

Slice, trim, replace, search, and more next.

String methods hub →

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.

8 people found this page helpful