obj.valueOf() returns the object’s primitive value when it has one. For a plain object, it usually returns the object itself.
Built-in wrappers and types override it: Number and Boolean return their primitives, and Date.valueOf() returns a timestamp number. JavaScript may call valueOf during numeric operations.
Syntax
Call obj.valueOf() like this. Start with this line.
JavaScript
obj.valueOf()
Call
What it does
obj.valueOf()
Returns a primitive when overridden; otherwise often the object itself.
({}).valueOf() === ({})
Each new object is a different reference — compare carefully.
new Date("2026-01-15").valueOf()
Returns the date as milliseconds since epoch.
No parameters. Plain objects typically get back the same object reference.
Library declarations
JavaScript
obj.valueOf()
JavaScript
object.valueOf(): Object
Parameters
Parameter
Description
(none)
Object.prototype.valueOf takes no parameters.
Return Value
Return Value
Description
any
A primitive value if the type provides one; for plain objects, usually the object itself.
JavaScript Examples
Plain Objects Return Themselves
Call valueOf on a normal object and compare references.
JavaScript
var user = { name: "Ada" };
var same = user.valueOf();
console.log(same);
console.log(same === user);
console.log(typeof same);
Same object.valueOf returns the object itself for plain objects.
Reference match.same === user is true.
Still an object.typeof stays "object".
Date valueOf Returns a Timestamp
Dates override valueOf with a number.
JavaScript
var day = new Date(Date.UTC(2026, 0, 15));
console.log(day.valueOf());
console.log(typeof day.valueOf());
console.log(day.valueOf() === day.getTime());