Operators
- (Subtraction)
JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax
num1 - num2
Description
The number to the right of the operator is subtracted from the number to the left of the operator. If either operand is a string, an attempt is made to convert the string to a number before performing the operation.
Example
The code in Listing 6.1 creates a string out of the number "45". The string is converted to a number before being subtracted from the number 25.
Listing 6.1 Using the Subtraction Operator
<html> <script language="JavaScript"> <!–– Hide //Declare the number 45 as a string aString = new String("45"); //Subtract 25 from 45 answer = aString - 25; document.write("answer = (45-25)<br>"); ... |
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.