2 Operators
2 Operators
Operator Detailed Description (with Important Points) Code Example Important Points for Exam
Type
Arithmetic - Used for basic arithmetic operations like addition, javascript let x = 10, y = 5; console.log(x + y); // 15 - Perform basic mathematical
Operators subtraction, multiplication, division, and modulus. console.log(x - y); // 5 console.log(x * y); // 50 operations. - % returns
- Includes: +, -, *, /, %, ++ (increment), -- (decrement). console.log(x / y); // 2 console.log(x % y); // 0 x++; remainder. - ++ and --
console.log(x); // 11 y--; console.log(y); // 4 increment/decrement values.
Assignment - Assign values to variables or update existing values. - let x = 10; - Assigns or updates values. -
Operators Includes: =, +=, -=, *=, /=, %= (shorthand for arithmetic x += 5; // x = x + 5 Shorthand available for
operations). console.log(x); // 15 arithmetic operations like +=, -=,
x -= 2; etc.
console.log(x); // 13
Comparison - Compare two values and return a boolean (true or let x = 10, y = "10"; - == compares values, ===
Operators false). - Includes: == (loose equality), === (strict console.log(x == y); // true compares both values and
equality), !=, !==, >, <, >=, <=. console.log(x === y); // false types. - Be familiar with != and !
== --> performs comparison after type console.log(x != y); // false ==.
conversion(loose equality). console.log(x !== y); // true
=== --> performs comparison without type console.log(x > 5); // true
conversion(coercien) console.log(x <= 10); // true
== coercien rules:
• Strings convert other operands to strings.
• Numbers convert other operands to numbers.
• Booleans convert to numbers (true → 1, false → 0).
FrontEnd Page 1