Much Like Algebra

JavaScript variables are containers for storing data values. In this example, price1, price2, and total, are variables:

HTML file: Displayed by browser:
<body>
<h1>JavaScript Variables</h1>
<p id="demo"></p>
<script>
   var price1 = 5;
   var price2 = 6;
   var total = price1 + price2;
   document.getElementById("demo").innerHTML = total;
</script>
</body>

JavaScript Variables

In programming, just like in algebra, we use variables (like price1) to hold values. Also, like in algebra, we use variables in expressions (total = price1 + price2). From the example above, you can calculate the total to be 11.

BackTable of ContentsNext