JavaScript Symbol valueOf() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Instance method

Definition

symbol.valueOf() returns the primitive symbol that a value stands for. Called on a normal symbol, it simply returns that same symbol. Called on a symbol wrapper object (made with Object(symbol)), it returns the symbol that is inside the wrapper.

You will almost never need it in everyday code, because JavaScript calls it for you when it needs the plain value. It helps you understand why a wrapper object and a symbol are two different things: Object(sym) === sym is false, but Object(sym).valueOf() === sym is true.

Remember
symbol.valueOf()

symbol           → the same symbol
Object(symbol)   → the symbol inside

typeof symbol            → "symbol"
typeof Object(symbol)    → "object"

Object(sym).valueOf() === sym

Syntax

Call it on a symbol or on a symbol wrapper object. It takes no arguments.

JavaScript
const id = Symbol("id");
const boxed = Object(id);

console.log(id.valueOf() === id);      // true
console.log(boxed.valueOf() === id);   // true
console.log(boxed === id);             // false
CallWhat it does
symbol.valueOf()Return the same symbol. It changes nothing.
Object(symbol).valueOf()Return the primitive symbol that is stored in the wrapper object.
Object(symbol)Wrap a symbol in an object. This is the only way to get a symbol object, because new Symbol() throws.
typeof valueTell the two apart: "symbol" for the primitive, "object" for the wrapper.

A standard JavaScript method (ES2015) on every symbol, from Symbol.prototype. No import required. Siblings: Symbol.for(), Symbol.keyFor(), toString(), [Symbol.toPrimitive]().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Symbol.prototype.valueOf()

// returns: a symbol
// throws : TypeError if called on something that is not a symbol

Parameters

ParameterDescription
(none)This method takes no parameters. Call it as symbol.valueOf().

Return Value

Return ValueDescription
symbolThe primitive symbol value. For a symbol this is the symbol itself, and for a wrapper object it is the symbol that was wrapped.
TypeError (thrown)Only when the method is borrowed and called on a value that is not a symbol, for example Symbol.prototype.valueOf.call("text").

JavaScript Examples

Example 1 — Get the Symbol Back

Call valueOf() on a local symbol and a shared symbol, and check the result.

JavaScript
const id = Symbol("id");
const copy = id.valueOf();

console.log("Same symbol: " + (copy === id));
console.log("Type: " + typeof copy);
console.log("Shared symbol: " + (Symbol.for("a").valueOf() === Symbol.for("a")));
console.log("Description kept: " + copy.description);
Try It Yourself

How It Works

  1. No change. A symbol is already a primitive value, so id.valueOf() gives back the very same symbol, and copy === id is true.
  2. Still a symbol. typeof copy is "symbol", not a string or an object.
  3. Shared symbols too. Symbol.for("a").valueOf() returns the registry symbol unchanged. The description is kept as well.

Example 2 — Wrap a Symbol in an Object

Use Object(symbol) to make a wrapper, compare it with the symbol, and try new Symbol(). The catch block prints the error type only.

JavaScript
const id = Symbol("id");
const boxed = Object(id);

console.log("typeof symbol: " + typeof id);
console.log("typeof boxed: " + typeof boxed);
console.log("boxed === id: " + (boxed === id));
console.log("boxed.valueOf() === id: " + (boxed.valueOf() === id));

try {
  new Symbol("id");
} catch (err) {
  console.log("new Symbol: " + err.name);
}
Try It Yourself

How It Works

  1. Two different types. Object(id) wraps the symbol in an object, so typeof boxed is "object" while typeof id stays "symbol".
  2. Unwrap with valueOf(). The wrapper is not strictly equal to the symbol, but boxed.valueOf() returns the symbol inside it, so that comparison is true.
  3. No new. Symbols are meant to be primitives, so new Symbol("id") throws a TypeError. Object(symbol) is the only way to get a wrapper.

Example 3 — Compare a Wrapper and Use It as a Key

See how ==, === and property keys treat a wrapper object, and how valueOf() reacts to a wrong value.

JavaScript
const id = Symbol("id");
const boxed = Object(id);
const data = { [id]: "found" };

console.log("boxed == id: " + (boxed == id));
console.log("boxed === id: " + (boxed === id));
console.log("As a key: " + data[boxed]);
console.log("Strict, after valueOf(): " + (boxed.valueOf() === id));

try {
  Symbol.prototype.valueOf.call("text");
} catch (err) {
  console.log("Not a symbol: " + err.name);
}
Try It Yourself

How It Works

  1. Loose and strict equality. == unwraps the object before comparing, so it is true. === never unwraps, so it is false.
  2. As a property key. When an object is used inside [ ], JavaScript first converts it to its primitive value. The wrapper becomes the symbol, so data[boxed] finds "found".
  3. Wrong receiver. valueOf() only accepts a symbol or a symbol wrapper. Borrowing it for the string "text" throws a TypeError.

Browser & Runtime Support

Symbol.prototype.valueOf() is part of ES2015 (ES6). Every current browser and Node.js has it.

✓ ES2015 · Widely supported

symbol.valueOf()

Supported in Chrome 38+, Edge 12+, Firefox 36+, Safari 9+, Opera 25+ and Node.js 0.12+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 38+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 36+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Opera 25+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 38+ · Chromium based
Supported
Node.js 0.12+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
symbol.valueOf() Excellent

Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Symbol at all.

Frequently Asked Questions

It returns the primitive symbol of a value. On a normal symbol it returns the same symbol. On a symbol wrapper object, made with Object(symbol), it returns the symbol that is inside the wrapper.
Object(symbol) creates an object, and a symbol is a primitive. An object and a primitive are never strictly equal. Use Object(symbol).valueOf() === symbol, or the loose comparison ==, which unwraps the object first.
Call Object(symbol). The usual new Symbol("id") does not work and throws a TypeError, because Symbol is not a constructor. Wrapper objects are rarely useful, so most code never needs one.
Almost never. JavaScript calls it for you when it needs the plain value, for example in a comparison with == or when a wrapper is used as a property key. Call it yourself only if you receive a wrapper object and want the symbol.
valueOf() returns the symbol itself. toString() returns text such as "Symbol(id)". Use valueOf() when you need the symbol, and toString() when you need something to print.

Next: [Symbol.toPrimitive]()

Learn which method JavaScript calls to turn a symbol into a primitive value, and which conversions still throw an error.

[Symbol.toPrimitive]() tutorial →

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