Arithmetic in JavaScript
Coding with JavaScript
🕑 This lesson will take about 10 minutes
In this lesson, you will learn how to use a range of arithmetic operators in JavaScript to assign values, modify variables and perform mathematical calculations.
If you have created your own variables and assigned them each a value (such as a string or integer), then you will already be familiar with the assignment operator which is a single = (equals sign).
Arithmetic operators include:
Addition +
Subtraction –
Division /
Multiplication *
Modulus %
Equals =
There are other arithmetic operators and functions (including exponentiation and square root) shown in the video and the sample code below.
The code below shows how you can use a range of operators when working with variable assignments and calculations.
Sample HTML & JavaScript code
Open the codepen snippet in a new tab/window and then click the Console button to view the output of the console.log() statements.
Next lesson: Strings