15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

488<br />

Using Operators<br />

VariableName can be any descriptive name. Because JavaScript is a casesensitive<br />

language, it treats My2008Tax as a completely different variable<br />

than my2008tax. Some programmers use uppercase letters to make variable<br />

names easier to find whereas others use all lowercase. To declare multiple<br />

variables, just cram them all on a single line, separated by a comma, such as<br />

var VariableName1, VariableName2, VariableName3;<br />

Using Operators<br />

The three types of operators used are mathematical, relational, and logical.<br />

Mathematical operators calculate numeric results such as adding, multiplying,<br />

or dividing numbers, as shown in Table 3-1.<br />

Table 3-1<br />

Mathematical Operators<br />

Mathematical Operator Purpose Example<br />

+ Addition 5 + 3.4<br />

- Subtraction 203.9 – 9.12<br />

* Multiplication 39 * 146.7<br />

/ Division 45 / 8.41<br />

% Modula division (returns the remainder) 35 % 9 = 8<br />

The + operator can also concatenate two strings together, such as “Hi<br />

there,” + “good looking.” This would create one string that contains<br />

“Hi there, good looking.”<br />

Relational operators compare two values and return a True or False value.<br />

The six comparison operators available are shown in Table 3-2.<br />

Table 3-2<br />

Relational Operators<br />

Relational Operator Purpose<br />

== Equal<br />

!= Not equal<br />

< Less than<br />

Greater than<br />

>= Greater than or equal to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!