Open In App

JavaScript Arithmetic Operators

Last Updated : 22 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

JavaScript Arithmetic Operators are the operator that operate upon the numerical values and return a numerical value.

Addition (+) Operator

The addition operator takes two numerical operands and gives their numerical sum. It also concatenates two strings or numbers.


Output
3
5hello

Subtraction (-) Operator

The subtraction operator gives the difference between two operands in the form of numerical value.


Output
3
NaN

Multiplication (*) Operator

The multiplication operator gives the product of operands where one operand is a multiplicand and another is multiplier.


Output
9
-16
NaN
Infinity
NaN

Division (/) Operator

The division operator provides the quotient of its operands where the right operand is the divisor and the left operand is the dividend.


Output
2.5
0.5
Infinity
Infinity
-Infinity

Modulus (%) Operator

The modulus operator returns the remainder left over when a dividend is divided by a divisor. The modulus operator is also known as the remainder operator. It takes the sign of the dividend.


Output
4
-2
1
1.5
-0
NaN

Exponentiation (**) Operator

The exponentiation operator gives the result of raising the first operand to the power of the second operand. The exponentiation operator is right-associative. 

In JavaScript, it is not possible to write an ambiguous exponentiation expression i.e. you cannot put an unary operator (+ / – / ~ / ! / delete / void) immediately before the base number.


Output
-16
32
27
15.588457268119896
0.01
512
NaN

Increment (++) Operator

The increment operator increments (adds one to) its operand and returns a value.

  • If used postfix with the operator after the operand (for example, x++), then it increments and returns the value before incrementing.
  • If used prefix with the operator before the operand (for example, ++x), then it increments and returns the value after incrementing.

Output
3
2
6
6

Decrement (- -) Operator

The decrement operator decrements (subtracts one from) its operand and returns a value.

  • If used postfix, with operator after operand (for example, x–), then it decrements and returns the value before decrementing.
  • If used prefix, with the operator before the operand (for example, –x), then it decrements and returns the value after decrementing.

Output
1
1
2
3

Unary Negation (-) Operator

This is a unary operator i.e. it operates on a single operand. It gives the negation of an operand.


Output
3
-3
3
-3

Unary Plus (+) Operator

This is a way to convert a non-number into a number. Although unary negation (-) also can convert non-numbers, unary plus is the fastest and preferred way of converting something into a number, because it does not perform any other operations on the number.


Output
4
2
1
0
0

Arithmetic Operators list

There are many arithmetic operators as shown in the table with the description.

OPERATOR NAME

USAGE

OPERATION

Addition Operatora + bAdd two numbers or concatenate the string
Subtraction Operatora – bDifference between the two operators
Multiplication Operatora * bMultiply two number
Division Operatora / bFind the quotient of two operands
Modulus Operatora % bFind the remainder of two operands
Exponentiation Operatora ** bRaise the Left operator to the power of the right operator 
Increment Operatora++
++a
Return the operand and then increase by one
Increase operand by one and then return
Decrement Operatora- –
– -a
Return operand and then decrease by one
Decrease operand by one and then return
Unary Plus(+)+aConverts NaN to number
Unary Negation (-)-aConverts operand to negative.

We have a complete list of Javascript operators, to check those please go through this Javascript Operators Complete reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.



Next Article

Similar Reads