HTML and CSS Reference
Adds the two numeric values; the result is
5 + 5
Combines the two string values; the result
“Java” + “Script”
Subtracts the second value from the first;
the result is 5.
10 - 5
Multiplies the two values; the result is 25.
5 * 5
Divides the value on the left by the value
on the right; the result is 5.
25 / 5
Obtains the modulus of 26 when it's
divided by 5. (Note: A modulus is a func-
tion that returns the remainder.) The result
26 % 5
Increments the value by 1; the result is 6.
Decrements the value by 1; the result is 5.
There are many other operators, too. All the examples here used literal values in the
expressions, but there are other options, too. You can use values returned by methods in
expressions if you choose, as in the following example:
document.write(Math.sqrt(25) - Math.sqrt(16));
number of methods that perform a variety of mathematical operations so that you don't
have to write the code to perform them yourself. Math.sqrt() is a method that returns
the square root of a number. In this case, I subtracted the square root of 16 from the
square root of 25 and passed the result to document.write() .
Thus far, I've been manipulating values and printing them directly to the page. The next
fundamental building block of writing scripts is temporary storage of those values so that
ables. A variable is a user-defined container that can hold a number, text, or an object.
Creating a variables and retrieving their values is simple: