Return to Kroll Design home page

JavaScript Tutorials

 
« Return

math operators

Here's some, but not all, of the JavaScript math operators:

Code:

<script type="text/javascript">
//<![CDATA[
x = 2;
y = 6;
document.write("x : ", x, "<br>");
document.write("y : ", y, "<br>");
document.write("z = x + y : ", x+y, "<br>");
document.write("z = y - x : ", y-x, "<br>");
document.write("z = x * y : ", x*y, "<br>");
document.write("z = y / x : ", y/x, "<br>");
document.write("z = y % x : ", y%x, " (modulus divides numbers and returns remainder)<br>");
document.write("x += y : ", x+=y, " (same as x = x +y.  \"+=\" is also an assignment operator.)<br>");
//]]>
</script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM