OPRATORS : operators are symbols or keywords used to perform operations on values and variables. They are the building blocks of JavaScript expressions and can manipulate data in various ways.
Arithmetic Operators : perform mathematical calculations like addition, subtraction, multiplication.
EXAMPLE:
let x = (100 + 50) * a;
Assignment operators : are used to assign values to variables. They can also perform operations like addition or multiplication while assigning the value.
EXAMPLE:
let x = 10;
x += 5;
Comparison operators : compare two values and return a boolean (true or false). They are useful for making decisions in conditional statements.
EXAMPLE:
let text1 = "20";
let text2 = "5";
let result = text1 < text2;
Logical operators : are mainly used to perform the logical operations that determine the equality or difference between the values.
EXAMPLE:
const a = true, b = false;
console.log(a && b); // Logical AND
console.log(a || b); // Logical OR
Bitwise operators : perform operations on binary representations of numbers.
EXAMPLE:
const res = 5 & 1; // Bitwise AND
console.log(res);
Ternary operator : is a shorthand for conditional statements. It takes three operands.
EXAMPLE:
const age = 18;
const status = age >= 18 ? "Adult" : "Minor";
console.log(status);
*Comma Operator : * mainly evaluates its operands from left to right sequentially and returns the value of the rightmost operand.
EXAMPLE:
let n1, n2
const res = (n1 = 1, n2 = 2, n1 + n2);
console.log(res);
Unary operators : operate on a single operand.
EXAMPLE:
let x = 5;
console.log(+x);
console.log(-x);
console.log(++x);
console.log(--x);
console.log(!x);
Relational operators : are used to compare its operands and determine the relationship between them. They return a Boolean value (true or false) based on the comparison result.
EXAMPLE:
const obj = { length: 10 };
console.log("length" in obj);
console.log([] instanceof Array);
BigInt operators : allow calculations with numbers beyond the safe integer range.
EXAMPLE:
const big1 = 123456789012345678901234567890n;
const big2 = 987654321098765432109876543210n;
console.log(big1 + big2);
String Operators : include concatenation (+) and concatenation assignment (+=), used to join strings or combine strings with other data types.
EXAMPLE:
const s = "Hello" + " " + "World";
console.log(s);
Optional chaining operator : allows safe access to deeply nested properties without throwing errors if the property doesnβt exist.
EXAMPLE:
const obj = { name: "Aman", address: { city: "Delhi" } };
console.log(obj.address?.city);
console.log(obj.contact?.phone);

Top comments (0)