JAVASCRIPT Tutorial

Operators in JS

Arithmetic operators are used to perform mathematical operations on numbers. The five basic arithmetic operators are:

  • Addition (+)
    • Adds two numbers together
    • Example: 5 + 10 = 15
  • Subtraction (-)
    • Subtracts one number from another
    • Example: 10 - 5 = 5
  • Multiplication (*)
    • Multiplies two numbers together
    • Example: 5 * 10 = 50
  • Division (/)
    • Divides one number by another
    • Example: 10 / 5 = 2
  • Modulo (%)
    • Returns the remainder after dividing one number by another
    • Example: 10 % 5 = 0

Javascript Example:

// addition

const num1 = 5;
const num2 = 10;
const sum = num1 + num2;
console.log(sum); // output: 15

// subtraction

const num3 = 10;
const num4 = 5;
const difference = num3 - num4;
console.log(difference); // output: 5

// multiplication

const num5 = 5;
const num6 = 10;
const product = num5 * num6;
console.log(product); // output: 50

// division

const num7 = 10;
const num8 = 5;
const quotient = num7 / num8;
console.log(quotient); // output: 2

// modulo

const num9 = 10;
const num10 = 5;
const remainder = num9 % num10;
console.log(remainder); // output: 0