Object Conversions

When a non-null object is used in a Boolean context, it converts to true . When an object is used in a
string context, JavaScript calls the toString( ) method of the object and uses the string value returned
by that method. When an object is used in a numeric context, JavaScript first calls the valueOf( ) method
of the object. If this method returns a primitive value, that value is used. In most cases, however, the
valueOf( ) method returns the object itself. In this case, JavaScript first converts the object to a string
with the toString( ) method and then attempts to convert the string to a number.

你可能感兴趣的:(JavaScript)