JavaScript Operators

JavaScript provides one‑ or two-character symbols (operators) for use in assigning values, performing math, increasing and decreasing counters, and making comparisons.

It is important to use operators correctly to avoid JavaScript errors. You can avoid many errors if you understand:

The following table lists available JavaScript operators.

Type of OperatorSymbolOperation Performed

Assignment Operator returns the assigned value

=

Assign a value

Arithmetic Operators return the resulting value

+ +=

Addition or Concatenate Addition (or Concatenate) and assign resulting value

 

- -=

Subtraction Subtraction and assign resulting value

 

* *=

Multiplication: Multiplication and assign resulting value

 

/ /=

Division Division and assign resulting value

 

% %=

Modulus (integer remainder of dividing 2 operands) Modulus and assign resulting value

 

++

Increment by 1 (x=x+1 is the same as x++)

 

--

Decrement by 1 (x=x–1 is the same as x––)

Comparison Operators return a Boolean value true or false

==

Test if Equal

 

!=

Test if Not Equal

 

>

Test if Greater Than

 

<

Test if Less Than

 

>=

Test if Greater Than or Equal To

 

<=

Test if Less Than or Equal To

Logical Operators return a Boolean value true or false

&&

And (test if both operands are true)

 

||

Or (test if one or the other operand is true)