ToPrimitive (Operator/internal)

An internal operator for converting values.

Availability:

ECMAScript edition - 2

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 TypeResult
UndefinedNo conversion, the input value is returned unchanged.
NullNo conversion, the input value is returned unchanged.
BooleanNo conversion, the input value is returned unchanged.
NumberNo conversion, the input value is returned unchanged.
StringNo conversion, the input value is returned unchanged.
ObjectThe 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

Cross-references:

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