String.prototype.valueOf() returns this string’s primitive text (same API as MDN String.prototype.valueOf()). Learn how it unwraps new String(...) objects, how it matches toString(), why it is often called by the engine, five examples, and try-it labs.
01
Kind
Instance method
02
Returns
string primitive
03
Parameters
None
04
vs toString
Same result
05
Wrong this
TypeError
06
Baseline
Widely available
Fundamentals
Introduction
Almost every string you write is already a primitive ("like this". valueOf() returns that primitive text — especially useful when you meet a Stringobject from new String(...).
For String values, the result is equivalent totoString(). MDN notes this method is usually called internally by JavaScript during coercion, not typed out by hand.
💡
Beginner tip
Prefer string literals "hi" over new String("hi"). When you already have a primitive, valueOf() just returns that same text.
Use String(x), template literals, or concatenation when you need to convert any value. Reserve String.prototype.valueOf for actual strings.
Applications
🎯 Common Use Cases
Unwrap String objects — turn new String(...) into a primitive.
Explicit APIs — document that you need a string primitive.
Understand coercion — engines often call valueOf for you.
Not for general coercion — prefer String(value).
Rare for literals — "hi".valueOf() is valid but usually unnecessary.
🧠 How valueOf() Works
1
Check this
Must be a string primitive or String object.
Guard
2
Reject other types
Non-string this → TypeError (no ToString coerce).
Error
3
Read the text
Take the primitive or the wrapped string contents.
Extract
4
✅
Return a string primitive
Same result as toString() for String.
Important
📝 Notes
Equivalent to toString() for String values.
Usually invoked by the language during coercion — not always written in app code.
Avoid new String() in modern code unless you have a special reason.
Wrappers and primitives are not equal with === until you unwrap.
Do not confuse with Number/Boolean valueOf — those return other primitives.
Compatibility
Browser & Runtime Support
String.prototype.valueOf() is Baseline Widely available — part of the language from early editions and safe everywhere.
✓ Baseline · Widely available
String.valueOf()
Safe for production in browsers and runtimes (Node.js, Deno, Bun). Simple unwrap of String objects to primitives — same text as toString().
UniversalWidely available
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
valueOf()Excellent
Bottom line: Use String.valueOf() to get the primitive text from a string or String object. It matches toString() for String; use String(value) for general conversion.
Wrap Up
Conclusion
String.prototype.valueOf() returns the underlying string text — especially useful when unwrapping new String(...). It matches toString(), takes no arguments, and throws if this is not a string.
Use valueOf() to unwrap String objects when needed
Remember it equals toString() for String
Use String(x) for converting non-strings
Know the engine may call it during coercion
❌ Don’t
Expect coercion of numbers via this method
Assume wrappers and primitives compare equal with ===
Call it on every literal “just in case”
Confuse it with Number.valueOf
Override String.prototype.valueOf in production code
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about String.valueOf()
Returns the string primitive — same as toString().
5
Core concepts
📝01
Returns
string primitive
API
🔢02
Parameters
none
Args
🔄03
toString
identical
Twin
❌04
Wrong this
TypeError
Limit
⚡05
Prefer
literals
Style
❓ Frequently Asked Questions
String.prototype.valueOf() returns the primitive string value — the text itself for a literal, or the string wrapped by a String object. It takes no arguments.
For String, they are equivalent — same result. MDN notes valueOf returns the same value as toString(). Either can unwrap a String object.
Usually no. JavaScript often calls valueOf internally during coercion. You may call it explicitly to document that you want the primitive string.
Calling String.prototype.valueOf with a non-string this (for example via call on a number) throws TypeError. It does not coerce other types to string.
Use String(value) (or template literals) when you need to convert any type to a string. valueOf only works on string primitives or String objects.
No. It returns a string primitive. String objects and primitives are not mutated by the call.
Did you know?
MDN says valueOf is usually called internally by JavaScript. When code does something like adding a String object to another value, the engine may reach for valueOf / toString to get a primitive — which is why you rarely write it by hand.