|
October 3, 1999 Type Conversion Tips: October 1999
Yehuda Shiran, Ph.D.
|
|
Data types are converted automatically in JavaScript during the course of script execution. A variable may hold a numeric value at one point of the script, and a string at another one. The following statements constitute a valid JavaScript script:
Although such conversions are allowed in JavaScript, they are not recommended. Mixing strings and numbers is sometimes necessary for certain operations. There are a few rules to remember. First, when an expression including both numbers and strings is evaluated to a single value, that value is a string. The number 6, for example, can be easily converted to the string
Notice that every expression including a string operand yields a string. The
People who read this tip also read these tips: Look for similar tips by subject: |