JavaScript Operators

JavaScript Tutorial

What Are JavaScript Operators?

JavaScript operators are symbols used to perform operations on values and variables.

Example:


 

 Types of JavaScript Operators

Arithmetic Operators

Used for mathematical calculations.

OperatorMeaningExampleResult
+Addition10 + 515
-Subtraction10 - 55
*Multiplication10 * 550
/Division10 / 52
%Modulus (remainder)10 % 31
**Exponent2 ** 38

Assignment Operators

Used to assign or update values.

OperatorMeaningExampleResult
=Assignx = 1010
+=Add and assignx += 5x = x + 5
-=Subtract and assignx -= 5x = x - 5
*=Multiply and assignx *= 5x = x * 5

Comparison Operators

Used to compare two values (returns true or false).

OperatorMeaningExampleResult
==Equal to10 == "10"true
===Strict equal10 === "10"false
!=Not equal10 != 5true
>Greater than10 > 5true
<Less than5 < 10true
>=Greater or equal10 >= 10true
<=Less or equal5 <= 10true

Logical Operators

Used to combine conditions.

OperatorMeaningExampleResult
&&ANDtrue && falsefalse
``OR
!NOT!truefalse

String Operators

Only + and += work for strings.

Increment and Decrement Operators

OperatorMeaningExample
++Increase by 1x++
--Decrease by 1x--

 Example with Output


 

Output:

Result: 30

 Summary

Js operators help perform:

  • Math operations

  • Assign values

  • Compare values

  • Combine conditions

  • Manipulate strings

You may also like...