# Operators

# Arithmetic operators

operator description example result
+ addition x + y sum of x and y
- subtraction x - y difference of x and y
* multiplication x * y product of x and y
/ division x / y quotient of x and y
% modulus x % y remainder/rest of x divided by y
** power x ** y x to the power y
++ post/pre increment x++
++x
post increment x
pre increment x
-- post/pre decrement x--
--x
post decrement x
pre decrement x

REMARK

  • The + operator can also be used to concatenate strings
const name = "John";
const surName = "Doe";
const fullName = name + " " + surName; // fullName = 'John Doe'
1
2
3

# Assignment operators

operator description example result
= assign x = y
+= add and assign x += y x = x + y
-= subtract and assign x -= y x = x - y
*= multiply and assign x *= y x = x * y
/= divide and assign quotient x /= y x = x / y
%= divide and assign modulus x %= y x = x % y

# Comparison operators

operator description example result
== equal x == y true if x is equal to y
=== identical x === y true if x is equal to y AND they are of the same type
!= not equal x != y true if x is not equal to y
!== not identical x !== y true if x is not equal to y OR they are not of the same type
< less than x < y true if x is less than y
<= less than or equal to x <= y true if x is less than or equal to y
> greater than x > y true if x is greater than y
>= greater than or equal to x >= y true if x is greater than or equal to y

# Logical operators

operator example result
&& x && y true if both x AND y are true
|| x || y true if either x OR y is true
! !x true if x is false (NOT true)
Last Updated: 4/22/2024, 2:26:56 PM