/

HTML / CSS / JavaScript Tutorial

JavaScript Operator: divide

[this page | pdf | back links]

In JavaScript, the / operator is the (binary) arithmetic operator for division.

 

For example, if x is 9 then y = x / 2 results in y becoming 4.5.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>table,th,tr,td {border: 1px solid black;
  border-collapse: collapse;}</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
document.getElementById("Example").innerHTML =
 'var x = 9 / 2;';
document.getElementById("Result").innerHTML = 9 / 2;
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators


Desktop view | Switch to Mobile