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
Fundamentals
Introduction
Almost every string you write in JavaScript is a primitivetypeof "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.
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.
Foundation
📝 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).
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
Compare
📋 Literal vs String() vs new String()
Literal "hi"
String("hi")
new String("hi")
typeof
"string"
"string"
"object"
instanceof String
false
false
true
=== "hi"
true
true
false
Best for?
Known text
Conversion
Almost never
Hands-On
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"
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.
=== 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.
Applications
🚀 Common Use Cases
Normalize mixed types — turn numbers, booleans, or nullish values into text for display or logging.
Form / API output — String(id) before concatenating into URLs or messages.
Safe Symbol labels — String(sym) when debugging keys that must become text.
Default empty text — String() 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.
Important
📝 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.
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
Conclusion
The String constructor is your conversion tool: String(value) returns a string primitive, while new String(value) returns a rarely useful object wrapper.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about the String constructor
Convert with String(); avoid new String().
5
Core concepts
📄01
Convert
String(x)
API
📝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").