JavaScript Object valueOf()
Examples
// Create a person object
const person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
let text = person.valueOf();
Try it Yourself »
const person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
let text = person.valueOf();
Description
The valueOf() method returns the primitive value of an object.
If the object has no primitive value, valueOf() returns the object itself.
The valueOf() method does not change the original object.
Syntax
object.valueOf()
Parameters
NONE
Return Value
The primitive value of an object.
Normally, it will return the object itself.
If the object is an array, it will return the primitive values.
Normally, it will return the object itself.
If the object is an array, it will return the primitive values.
Browser Support
valueOf() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |