JavaScript object valueOf() method

Definition and usage

valueOf() The method returns the original value of the object.

If an object does not have an original value, then valueOf() Returns the object itself.

valueOf() The method does not change the original object.

Note:fruits.valueOf() Returns the same as fruits Same value.

Instance

Example 1

Get the value of fruits:

const fruits = ["Banana", "Orange", "Apple", "Mango"];
const myArray = fruits.valueOf();

Try it yourself

Example 2

The return value of fruits.valueOf() is the same as fruits:

const fruits = ["Banana", "Orange", "Apple", "Mango"];
const myArray = fruits;

Try it yourself

Syntax

object.valueOf()

Parameter

No parameters.

Return value

Type Description
Object

The original value of the object.

If an object does not have an original value, the valueOf() returns the object itself.

Browser support

valueOf() Is ECMAScript1 (ES1) feature.

All modern browsers support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Stöd Stöd Stöd Stöd Stöd Stöd

Relaterade sidor

JavaScript objekt

JavaScript objekt definition

JavaScript objektmetoder

JavaScript objekter egenskaper