
JavaScript Operators
What are Operators? Operators are symbols used to perform operations on values or variables. Example: let result = 5 + 3; Here, '+' is an operator that adds two numbers. Types of JavaScript Operators Arithmetic Operators Assignment Operators Comparison Operators Logical Operators String Operators 1. Arithmetic Operators Used for mathematical calculations. Addition (5 + 3) Subtraction (5 - 3) Multiplication (5 * 3) / Division (10 / 2) % Modulus (10 % 3) Increment / Decrement: x++ Post Increment ++x Pre Increment x-- Post Decrement --x Pre Decrement Example: let x = 5; x++; console.log(x); Output: 6 2. Assignment Operators Used to assign values to variables. = x = 5 += x += 5 (x = x + 5) -= x -= 5 (x = x - 5) *= x *= 5 (x = x * 5) /= x /= 5 (x = x / 5) Example: let x = 10; x += 5; console.log(x); Output: 15 3. Comparison Operators Used to compare two values. Result is true or false. == 5 == '5' → true === 5 === '5' → false != 5 != 3 → true 5 > 3 → true < 5 < 3 → false = 5 >= 5 → true <=
Continue reading on Dev.to JavaScript
Opens in a new tab



