There are three conversions to study. Obviously string values will remain as they are.
This table summarizes the effects of converting values to strings:
| Value: | Resulting string: |
|---|---|
| Zero | "0" |
| null | "null" |
| Undefined value | "undefined" |
| NaN | "NaN" |
| Infinity | "Infinity" |
| Negative infinity | "-Infinity" |
| Numeric value | That numeric value as a sequence of characters. |
| Boolean true | "true" |
| Boolean false | "false" |
| Object | Result of Object.toString(). |
| Object lacking a toString() method. | Result of conversion of result from Object.valueOf() method. |
| Object without toString() or valueOf() methods. | An error |
| Array | Comma elements joined by a comma. |
| Function | Depends on implementation. |
Converting objects to strings will first attempt to use the toString() method and then the valueOf() method, converting the resulting number to a string after that.
| Prev | Home | Next |
| Conversion to a number | Up | Conversion to an object |
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. | ||