JavaScript tutorial:
valueOf method

 

Applies to: Array Object, Boolean Object, Date Object, Function Object, Number Object, Object Object, String Object

The valueOf method is use to get the primitive value of the specified object.

Syntax

object.valueOf( )

The object argument is any JavaScript object.

Return value

Returns the primitive value of the specified object.

Example

The valueOf method is defined differently for each intrinsic JavaScript object.

Object

Return Value

Array

The elements of the array are converted into strings, and the strings are concatenated together, separated by commas. This behaves the same as the Array.toString and Array.join methods.

Boolean

The Boolean value.

Date

The stored time value in milliseconds since midnight, January 1, 1970 UTC.

Function

The function itself.

Number

The numeric value.

Object

The object itself. This is the default.

String

The string value.

The Math object does not have a valueOf method.

See also: toString Method