This operator converts objects to primitive values.
The ToPrimitive operator takes a value argument and an optional preferred type argument and converts its input to a primitive type from an object representation.
Input Type | Result |
---|---|
Undefined | No conversion, the input value is returned unchanged. |
Null | No conversion, the input value is returned unchanged. |
Boolean | No conversion, the input value is returned unchanged. |
Number | No conversion, the input value is returned unchanged. |
String | No conversion, the input value is returned unchanged. |
Object | The default value defined by the object's internal DefaultValue method is returned. A coercion to the preferred type happens and is context dependent on where the result is being assigned. |
See also: | Cast operator, Conversion, Implicit conversion, Number, Type conversion |
ECMA 262 edition 2 - section - 8.6.2.6
ECMA 262 edition 2 - section - 9.1
ECMA 262 edition 3 - section - 8.6.2.6
ECMA 262 edition 3 - section - 9.1
Prev | Home | Next |
Topic classification | Up | ToString |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |