HTML and CSS Reference

In-Depth Information

programs that can be written are basic mathematical statements, so

we'll start with them. Open the JavaScript console in your preferred

web browser, and follow along with the examples.

Arithmetic

In this section, you'll learn how basic arithmetic operations are repre-

sented in JavaScript. The examples are all shown in the Firefox Web

Console, but you should see the same results in any other browser.

Basic addition, subtraction, multiplication,

and division are written in much the same

way as they were in your high school

topic. The asterisk (
*
) is used to indicate

multiplication and the forward slash (
/
)

division. Expressions and their values are

shown in the console output. Try typing a

few expressions and pressing Enter.

Programmers refer to numbers as
operands

and symbols as
operators
. The entire com-

bination is called an
expression
. A sequence of expressions terminated

by a semicolon is a
statement
. The following diagram should help you

get the vocabulary straight.

statement

Operator

2 + 2;

2 + 2 ;

operand

operand

Expression

Any number of operands and operators can be chained together, but

they're not evaluated left to right. Some operators are more important

than others and are always evaluated first.