HTML and CSS Reference
In-Depth Information
.
Output
FIGURE 14.2
Attempting to write
an object to the
page.
That's the string representation of the document object. Many programming languages
would print an error if you tried to use an object like document with a method that
accepts a string. Not JavaScript; it makes do with what you give it.
Operators and Expressions
In the previous examples, we supplied a single value to the document.write() method
as an argument. In the same context, we could have also used an expression. An expres-
sion is a snippet of code that becomes a value once it has been evaluated. You may rec-
ognize the term expression from math, and indeed, many expressions are mathematical
expressions. Here's an example of a mathematical expression passed to
document.write() :
<script type=”text/javascript”>
document.write(10 * 50);
</script>
In this case, JavaScript will multiply 10 by 50 and then pass in the result as the argu-
ment. That's an expression. There are also string expressions; you can use the + operator
to join strings together, like this:
<script type=”text/javascript”>
document.write(“An” + “ “ + “expression.”);
</script>
Expressions are built using operators. You've already seen a couple, * for multiplication
and + for combining strings. Table 14.1 lists more operators provided by JavaScript,
along with examples. (For a full list of all the supported operators, refer to the online
JavaScript documentation.)
14
 
Search WWH ::




Custom Search