Arithmetic operators in Javascript

·

2 min read

With mathematics, you can perform arithmetic operations annotated as + for addition, - for subtraction, / for division, and X for multiplication. In programming languages such as javascript, you can perform similar arithmetic operations just like math with the help of characters called arithmetic operators.

Addition ('+')

You can add two or more numbers/ strings with the help of '+' operator

Examples

const a = 2, b = 3;
const c = a + b
console.log({c})

output
{c:5}

When + is used with a string, it is called string concatenation

const a = 'Hello', b = ' World';
const c = a + b
console.log({c})

output
{c:'Hello World'}

Subtraction ('-')

You can subtract two or more numbers with the help of '-' operator

Examples

const a = 4, b = 3;
const c = a - b
console.log({c})

output
{c:1}

Multiplication ('*')

You can multiply two or more numbers with the help of '+' operator

Examples

const a = 2, b = 3;
const c = a + b
console.log({c})

output
{c:5}

Division ('/')

You can divide two or more numbers with the help of '/' operator

Examples

const a = 6, b = 3;
const c = a / b
console.log({c})

output
{c:2}

Remainder ('%')

You can find the remainder after dividing two or more numbers with the help of the '%' operator

Examples

const a = 7, b = 3;
const c = a % b
console.log({c})

output
{c:1}

Moreover, Javascript provides the Math class/instance/object which exposes several methods and properties that enable us to perform complex mathematical operations such as rounding off, truncation, finding the cosine, sine, and tan of an angle and.
We will discuss more Math properties and methods in my next post.
Cheers!