Javascript operators

Created By: chatGPT

JavaScript provides various types of operators that can be used to perform operations on values and variables. These operators can be classified into several categories based on their functionality. Below are some of the key types of operators in JavaScript:
Arithmetic Operators are used to perform basic mathematical operations. They include addition, subtraction, multiplication, division, and modulus.
let a = 10;
let b = 5;

let sum = a + b;       // Addition
let difference = a - b; // Subtraction
let product = a * b;    // Multiplication
let quotient = a / b;   // Division
let remainder = a % b;  // Modulus
Comparison Operators are used to compare two values and return a boolean value (true or false). These include equality, inequality, and comparison operators.
let x = 10;
let y = 20;

let isEqual = (x === y);   // Strict equality
let isNotEqual = (x !== y); // Strict inequality
let isGreater = (x > y);    // Greater than
let isLess = (x < y);       // Less than
Logical Operators are used to combine multiple boolean expressions. The most common logical operators are AND (&&), OR (||), and NOT (!).
let isAdult = true;
let hasPermission = false;

let canAccess = isAdult && hasPermission; // AND
let canDoSomething = isAdult || hasPermission; // OR
let deniedAccess = !canAccess; // NOT
Assignment Operators are used to assign values to variables. The assignment operator is '=', but there are compound assignment operators for operations like addition and multiplication.
let a = 5;
a += 2; // a = a + 2
let b = 10;
b *= 2; // b = b * 2
Unary Operators operate on a single operand, such as increment (++) and decrement (--). These are often used to increase or decrease the value of a variable by one.
let count = 0;
count++; // Increment count by 1
count--; // Decrement count by 1
Ternary Operator is a shorthand for an if-else statement and takes three operands. It is often used for conditional expressions.
let age = 18;
let eligibility = (age >= 18) ? 'Eligible' : 'Not eligible';
Bitwise Operators perform operations on binary numbers. They include AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>).
let x = 5;  // binary: 0101
let y = 3;  // binary: 0011

let bitwiseAnd = x & y;  // Result: 1 (0001)
let bitwiseOr = x | y;   // Result: 7 (0111)
Type Operators are used to check the data type of a variable. The most commonly used is typeof, which returns a string indicating the type of the unevaluated operand.
let name = 'John';
let age = 30;

console.log(typeof name); // 'string'
console.log(typeof age);  // 'number'
Introduction And SetupVariablesData TypesMethodsControl FlowFunctionsOperatorsData StructuresCommentsSyntaxEvent HandlingError HandlingPrimitive Data TypesReference Data TypesConstLetVarStringNumberBooleanNullUndefinedSymbolObjectArrayTemplate LiteralsArrow FunctionsRegular FunctionsCallApplyBindAsync FunctionsPromisesCallback FunctionsIf StatementElse StatementSwitch StatementFor LoopWhile LoopDo While LoopFor EachBreak StatementContinue StatementTry CatchThrowFinallyScopeClosureThis KeywordPrototypesInheritanceConstructor FunctionsClass SyntaxStatic MethodsGettersSettersSpread OperatorRest OperatorDestructuring AssignmentMap MethodFilter MethodReduce MethodEvent ListenersDom ManipulationInnerHTMLQuerySelectorAddEventListenerPreventDefaultStopPropagationTimeoutsIntervalsJsonLocal StorageSession StorageRegexMath ObjectDate ObjectString MethodsArray MethodsObject MethodsDeep CloningShallow CloningCallback HellPromise ChainingAsync AwaitMap Vs ForEachFilter Vs ReduceNullish Coalescing OperatorOptional ChainingTypeof OperatorInstanceof OperatorStrict EqualityLoose Equality