Working with JavaScript Operators

What if you wanted to manipulate your data in JavaScript code? Say, for example, that you needed to multiple 219 by 45—how would you do it? In JavaScript, you can use the multiplication operator (*). Here's an example showing how this works:

Listing . ch06_05.html
 
<HTML>
    <HEAD>
        <TITLE>
            Using Operators In JavaScript
        </TITLE>
    </HEAD>

    <BODY>
        <CENTER>
            <H1>
                Using Operators In JavaScript
            </H1>
        </CENTER>

        <SCRIPT LANGUAGE="JavaScript">
            var result
					result = 219 * 45
					document.writeln("219 * 45 = " +  result)
        </SCRIPT>
    </BODY>
</HTML>

You can see the results of this code in Figure 6-5.

Figure 6-5. Using JavaScript operators in Internet Explorer.

As you might expect, there are many operators available in JavaScript. For ...

Get Real World XML 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.