JavaScript supports various types of operators that perform different operations on variables and values. These include:
let x = 10; let y = 3; let sum = x + y; // Addition let difference = x - y; // Subtraction let product = x * y; // Multiplication let quotient = x / y; // Division let remainder = x % y; // Modulus
Assignment Operators:*
let a = 5; a += 3; // Equivalent to: a = a + 3;
Comparison Operators:
let p = 10; let q = 5; console.log(p > q); // Greater than console.log(p < q); // Less than console.log(p === q); // Equal to (strict equality) console.log(p !== q); // Not equal to (strict inequality)
Logical Operators:
let isLoggedIn = true; let isAdmin = false; console.log(isLoggedIn && isAdmin); // Logical AND console.log(isLoggedIn || isAdmin); // Logical OR console.log(!isAdmin); // Logical NOT
Unary Operators:
let count = 5; count++; // Increment console.log(count); // Outputs: 6
Conditional (Ternary) Operator:
let age = 18; let status = (age >= 18) ? "Adult" : "Minor"; console.log(status); // Outputs: "Adult"
String Concatenation Operator:
let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; // String concatenation console.log(fullName); // Outputs: "John Doe"