home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeActionScript: The Definitive GuideSearch this book

5.3. Arithmetic Operators

The arithmetic operators perform mathematical operations on numeric operands. If you use non-numeric operands with the arithmetic operators, ActionScript will attempt to convert the foreign data to a number. For example, false - true evaluates to -1 because false converts to the numeric value and true converts to 1. Similarly, the expression "3" * "5" results in the number 15, because the strings "3" and "5" are converted to the numbers 3 and 5 before the multiplication is performed. The + operator, however, presents a special case: when used with at least one string operand, it performs a string concatenation operation, not mathematical addition.

If an attempt to convert a non-numeric operand to a number fails, the operand will be set to the special numeric value NaN. This results in the entire operation yielding NaN. Refer to Table 3-1 for details on numeric conversion.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.