#atom
ID: JS-002
Date: [Insert Date]
Content:
Operators in JavaScript are symbols used to perform operations on operands (values or variables). JavaScript supports a wide range of operators, including arithmetic, comparison, logical, assignment, and more.
Categories of Operators:
-
Arithmetic Operators:
Used for mathematical operations.+(Addition)-(Subtraction)*(Multiplication)/(Division)%(Modulus/Remainder)**(Exponentiation)++(Increment)--(Decrement)
Example:
let a = 10; let b = 3; console.log(a + b); // 13 console.log(a ** b); // 1000 -
Comparison Operators:
Used to compare two values.==(Equal to)===(Strict equal to)!=(Not equal to)!==(Strict not equal to)>(Greater than)<(Less than)>=(Greater than or equal to)<=(Less than or equal to)
Example:
console.log(5 === '5'); // false console.log(5 == '5'); // true -
Logical Operators:
Used to combine or negate conditions.&&(Logical AND)||(Logical OR)!(Logical NOT)
Example:
console.log(true && false); // false console.log(true || false); // true console.log(!true); // false -
Assignment Operators:
Used to assign values to variables.=(Assignment)+=(Add and assign)-=(Subtract and assign)*=(Multiply and assign)/=(Divide and assign)%=(Modulus and assign)**=(Exponentiation and assign)
Example:
let x = 5; x += 3; // x = x + 3 console.log(x); // 8 -
Ternary Operator:
A shorthand forif-else.condition ? expr1 : expr2
Example:
let age = 20; let status = age >= 18 ? 'Adult' : 'Minor'; console.log(status); // "Adult" -
Type Operators:
Used to check the type of a value.typeof(Returns the type of a value)instanceof(Checks if an object is an instance of a class)
Example:
console.log(typeof 42); // "number" -
Bitwise Operators:
Used to perform bit-level operations.&(AND)|(OR)^(XOR)~(NOT)<<(Left shift)>>(Right shift)>>>(Unsigned right shift)
Example:
console.log(5 & 3); // 1 -
Other Operators:
,(Comma operator)delete(Deletes a property from an object)new(Creates an instance of an object)in(Checks if a property exists in an object)
Example:
const obj = { a: 1 }; console.log('a' in obj); // true
Connections:
Connections:
Sources: