Web Analytics

JavaScript Operators

Beginner ~15 min read

Arithmetic Operators

Arithmetic operators are used to perform arithmetic on numbers.

HTML
CSS
JS

Assignment Operators

Assignment operators assign values to JavaScript variables.

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

Comparison Operators

Comparison operators are used in logical statements to determine equality or difference between variables or values.

HTML
CSS
JS
Always use === (strict equality) instead of ==. The == operator performs type coercion, which can lead to unexpected results (e.g., 0 == '0' is true).

Logical Operators

Logical operators are used to determine the logic between variables or values.

HTML
CSS
JS

Summary

  • Arithmetic operators perform math (+, -, *, /).
  • Assignment operators assign values (=, +=).
  • Comparison operators compare values (===, >, <).
  • Logical operators combine booleans (&&, ||, !).

Quick Quiz

What is the result of 5 === '5'?

A
true
B
false
C
undefined
D
NaN