Operator

An operator is a symbol or keyword in programming that specifies an operation to be performed on one or more operands. Operators are used to manipulate data and variables.

Operators are essential components in programming languages and can perform a variety of operations, such as arithmetic, comparison, logical, and assignment operations. They help in constructing expressions and executing computations.

Example: Here’s an example in JavaScript demonstrating various operators:

let a = 10;
let b = 5;

// Arithmetic Operators
let sum = a + b;  // 15
let difference = a - b;  // 5
let product = a * b;  // 50
let quotient = a / b;  // 2
let remainder = a % b;  // 0

// Comparison Operators
console.log(a > b);  // true
console.log(a < b);  // false
console.log(a == b);  // false
console.log(a != b);  // true

// Logical Operators
let x = true;
let y = false;
console.log(x && y);  // false
console.log(x || y);  // true
console.log(!x);  // false

// Assignment Operators
let c = 20;
c += 10;  // c is now 30

// Unary Operators
let d = 1;
d++;  // d is now 2
d--;  // d is now 1

// Ternary Operator
let isEven = (a % 2 === 0) ? 'Even' : 'Odd';  // 'Even'
console.log(isEven);