The valueOf() method returns the array itself—the same object reference as this. It does not build a string or copy data. This tutorial explains why it exists, how it differs from toString(), and when (rarely) you might call it directly.
01
Syntax
valueOf()
02
Returns
Same array
03
Reference
arr === result
04
vs toString
Object vs string
05
Coercion
toString wins
06
ES3
Universal
Fundamentals
Introduction
Every JavaScript object inherits valueOf() from Object.prototype. Arrays override it to return this—the array you called it on. So numbers.valueOf() gives you back numbers, not a flattened string like "1,2,3".
You will rarely call valueOf() directly in everyday code. It matters for understanding type coercion, the object model, and how arrays behave when JavaScript converts values.
Concept
Understanding the valueOf() Method
array.valueOf() returns the array object unchanged. Mutations through the returned reference affect the original array because they are the same object.
When an array is turned into a string (for example "Values: " + arr), JavaScript uses toString(), which produces comma-separated text. valueOf() is not the method that creates that string.
💡
Beginner Tip
Think of valueOf() as “give me the array object” and toString() as “give me a readable string of its elements.”
Foundation
📝 Syntax
General form of Array.prototype.valueOf:
JavaScript
array.valueOf()
Parameters
None.
Return value
The same array object (this).
Common patterns
arr.valueOf() — returns arr (same reference).
arr === arr.valueOf() — always true.
String(arr) or arr.toString() — for display strings.
Number(arr) — uses different coercion rules (often NaN).
Cheat Sheet
⚡ Quick Reference
Question
Answer
Return type
Array (object)
Same as original?
arr === arr.valueOf()
String display
Use toString()
Compare two arrays
Not with valueOf
Mutates array?
No (but returns mutable ref)
Compare
📋 valueOf() vs toString() vs JSON.stringify()
valueOf returns the object; toString and JSON produce strings.
valueOf
array ref
Object
toString
comma str
Display
toLocaleString
locale str
i18n
JSON.stringify
JSON text
Data
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
Custom objects — contrast with Date, where valueOf returns a number.
Debugging identity — confirm you still hold the same array reference.
Legacy libraries — rare explicit calls in older codebases.
When not to use — string display, deep equality, or cloning.
🧠 How valueOf() Fits In
1
Call valueOf()
Array override runs.
Invoke
2
Return this
Same array object reference.
Object
3
Need a string?
Engine calls toString() instead.
Coerce
4
✅
Comma text
Display via toString path.
Important
📝 Notes
Returns the array object, not a primitive string or number.
arr === arr.valueOf() is always true.
Does not clone or copy elements.
String output comes from toString(), not valueOf().
Do not use for comparing array contents.
Dates override valueOf to return milliseconds—arrays do not.
ES3—universal browser support.
Compatibility
Browser & Runtime Support
Array.prototype.valueOf() has been available since ES3 as part of the core object model inherited from Object.prototype.
✓ Baseline · ES3
Array.prototype.valueOf()
Supported in every browser and Node.js version—including very old environments. Behavior is identical everywhere.
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
Array.valueOf()Excellent
Bottom line: Safe everywhere. You will almost always use the array directly instead of calling valueOf explicitly.
Wrap Up
Conclusion
valueOf() on arrays simply returns the array itself. For readable text, use toString() or join(). For data, use JSON.stringify(). Knowing valueOf() clarifies how JavaScript treats arrays during type conversion.
Next, learn with() to replace an element at an index without mutating the original array.
valueOf() returns the array itself—the same object reference. For arrays, it does not convert elements to a string or number; it simply returns this.
No. valueOf() only returns a reference to the existing array. However, because it returns the same array, any changes you make through that reference affect the original.
Yes. arr === arr.valueOf() is true. They point to the same array object in memory.
valueOf() returns the array object. toString() returns a comma-separated string of elements. When JavaScript needs a string (e.g. in concatenation), it uses toString(), not the raw array from valueOf().
No. array1.valueOf() === array2.valueOf() compares references, so two separate arrays with identical contents still return false. Use a deep comparison or JSON.stringify for content equality.
Array.valueOf() has been available since ES3 and works in every browser and Node.js environment.
Did you know?
Wrapper objects like new Number(5) use valueOf() to unwrap to a primitive. Arrays are already objects, so their valueOf() just returns this rather than unboxing to a number or string.