Conversion to a number (Definition)

Converting values to a numeric representation.

There are three conversions to study. Obviously numeric values will remain as they are.

This table summarizes the effects of converting values to numbers:

Value:Numeric equivalent:
Undefined valueNaN
Empty string0
Numeric stringNumeric value of string
Non-numeric stringNaN
Boolean true1
Boolean false0
ObjectResult of Object.valueOf().
Object lacking a valueOf() method.Result of conversion of result from Object.toString() method.
Object without toString() or valueOf() methods.An error
ArrayNo direct numeric equivalent

Converting objects to numbers will first attempt to use the valueOf() method and then the toString() method, converting the resulting string to a number after that.

There is no proper numeric equivalent for an array. The ECMA standard does not address this either.