Operators in JavaScript
Operators are symbols that allow us to perform operations on variables and values.
Types of Operators
- Arithmetic Operators: Used for mathematical calculations (+, -, *, /).
- Assignment Operators: Assign values to variables (=, +=, -=).
- Comparison Operators: Compare values (==, ===, !=, >, <).
- Logical Operators: Used for logical operations (&&, ||, !).
Example: Arithmetic Operators
let x = 5;
let y = 3;
console.log(x + y); // 8
console.log(x * y); // 15
Activity
Try It Yourself!
Use different operators with x = 10
and y = 2
to see the results.
Quiz
Quick Quiz
- What operator would you use to add two numbers?
- Which operator is used for strict equality?
- What does the
&&
operator represent?
Answers: +; ===; logical AND.