Skip to main content

Operator

Operators in JavaScript

Arithmetic Operators

Perform basic math operations:

OperatorExampleResult
+2 + 35
-5 - 23
*4 * 28
/10 / 25
%7 % 31
**2 ** 38

Example

let a = 2 + 1   // 3
let b = a - 1 // 2
let c = b * 3 // 6
let d = c / 2 // 3
let e = 8 % 3 // 2
let f = 2 ** 3 // 8

Assignment Operators

Assign or update values:

OperatorExampleMeaning
=x = 5Assign 5 to x
+=x += 3x = x + 3
-=x -= 2x = x - 2
*=x *= 4x = x * 4
/=x /= 2x = x / 2

Example:

let x = 5  // 5
x += 3 // 8
x -= 2 // 6
x *= 4 // 24
x /= 2 // 12

Comparison Operators

Return true or false by comparing values:

OperatorExampleResult
==5 == '5'true (loose equality)
===5 === '5'false (strict equality)
!=5 != 10true
!==5 !== '5'true
<3 < 5true
>7 > 2true
<=4 <= 4true
>=6 >= 8false

Logical Operators

Work with boolean values:

OperatorExampleMeaning
&&true && falseAND (both true)
``
!!trueNOT (negation)