JavaScript Operators
Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers.
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.
=== (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.
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'?
Enjoying these tutorials?