3.12. Type Conversion SummaryAs each datatype has been described in the previous sections, I've discussed how values of each type convert into values of other types. The basic rule is that when a value of one type is used in a context that requires a value of some other type, JavaScript automatically attempts to convert the value as needed. So, for example, if a number is used in a Boolean context, it is converted to a boolean. If an object is used in a string context, it is converted to a string. If a string is used in a numeric context, JavaScript attempts to convert it to a number. Table 3-3 summarizes each of these conversions and shows the conversion that is performed when a particular type of value is used in a particular context.
|