JavaScript Operators


JavaScript Assignment

The assignment operator (=) is used to give a value to a variable.


JavaScript Addition

The plus sign, known as the Addition Operator (+), is used to add numbers.


JavaScript Multiplication

The Multiplication Operator represented by (*) is used to multiply numbers.


Types of JavaScript Operators

There exist various kinds of JavaScript operators:

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • String Operators
  • Logical Operators
  • Bitwise Operators
  • Ternary Operators
  • Type Operators

JavaScript Arithmetic Operators

Arithmetic Operators help us do math with numbers:

Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement

Note : Arithmetic operators are fully described in the JS Arithmetic chapter.


JavaScript Assignment Operators

Assignment operators are like tools that give values to JavaScript variables.

The Addition Assignment Operator (+ =) is used to add a value to a variable.

Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y

Note : Assignment operators are fully described in the JS Assignment chapter.


JavaScript Comparison Operators

Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator

Note : Comparison operators are fully described in the JS Comparisons chapter.


JavaScript String Comparison

You can use the same comparison operators for strings as well.

Note that strings are compared alphabetically:


JavaScript String Addition

You can use the + sign to join or connect strings together.

The + = assignment operator can also be used to add (concatenate) strings:

Note : When used on strings, the + operator is called the concatenation operator.


Adding Strings and Numbers

When you add two numbers together, you get their total. But if you add a number and a string, you'll get a string as the result.

Note : If you mix a number with a word, you'll get a word as the answer!


JavaScript Logical Operators

Operator Description
&& logical and
|| logical or
! logical not