/

HTML / CSS / JavaScript Tutorial

JavaScript Operator: multiply assignment

[this page | pdf | back links]

In JavaScript, the *= operator is the assignment operator with multiplication.

 

For example, if x is 5 and y is 8 then y *= x results in x remaining 5 and y = y * x, so y becomes 40.

 

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>
<th>Resulting value of <code>y</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Resultx"></code></td>
<td><code id="Resulty"></code></td>
</tr>
</table>

<script>
document.getElementById("Example").innerHTML =
  'var x = 5;<br>' +
  'var y = 8;<br>' +
  'y *= x;';
var x = 5; var y = 8; y *= x;
document.getElementById("Resultx").innerHTML=x;
document.getElementById("Resulty").innerHTML=y;
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators


Desktop view | Switch to Mobile