This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

valueOf

Summary

Returns the primitive value of the specified object.

Syntax

object.valueOf( )

Examples

The following example illustrates the use of the valueOf method with a date object.

var myDate = new Date();
 myDate.setFullYear(2100, 5, 5);
 if (myDate.getTime() == myDate.valueOf())
     document.write("values are the same");
 else
     document.write("values are different");

 // Output: values are the same

Remarks

The required object reference is any intrinsic JavaScript object.

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

ObjectReturn Value
ArrayReturns the array instance.
BooleanThe Boolean value.
DateThe stored time value in milliseconds since midnight, January 1, 1970 UTC.
FunctionThe function itself.
NumberThe numeric value.
ObjectThe object itself. This is the default.
StringThe string value.

The Math and Error objects do not have a valueOf method.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article