Arithmetic Operators
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 12 of 77.
Operators are used to perform operations on values.
First we will discuss the most basic arithmetic operators, they may be familiar from math classes.
| Operator | Operation | Example |
|---|---|---|
| + | Addition | 3 + 2 = 5 |
| - | Subtraction | 3 - 2 = 1 |
| * | Multiplication | 3 * 2 = 6 |
| / | Division | 4 / 2 = 2 |
Let's see a usage example,
let a = 3
let b = 5
let c = a + b // c holds 8Challenge
BeginnerWrite a code that initializes two variables, a and b, with the values 5.2 and 2.6 (respectively).
After that, initialize another variable c that will hold the result of a / b.
Cheat sheet
Arithmetic operators perform mathematical operations on values:
| Operator | Operation | Example |
|---|---|---|
| + | Addition | 3 + 2 = 5 |
| - | Subtraction | 3 - 2 = 1 |
| * | Multiplication | 3 * 2 = 6 |
| / | Division | 4 / 2 = 2 |
Example usage:
let a = 3
let b = 5
let c = a + b // c holds 8Try it yourself
// Type your code below
// Don't change the line below
console.log(`a = ${a}, b = ${b}, c = ${c}`);This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False