Javascript Operators :

In JavaScript, operators are symbols or keywords that perform operations on operands (values or variables) and produce a result. JavaScript provides a wide range of operators that can be used for arithmetic, assignment, comparison, logical operations, and more. Here's an overview of the main categories of JavaScript operators:

  1. Arithmetic Operators:
    • Addition (+), subtraction (-), multiplication (*), and division (/) operators perform basic mathematical operations on numbers.
      E.g:
      A = 10
      B = 20
      A + B = 30
      A - B = -10
      A * B = 200
      B / A = 2

    • Remainder/Modulus (%) operator returns the remainder of a division operation.
      E.g:
      A = 10
      B = 20
      B % A = 0

    • Increment (++) and decrement (--) operators increase or decrease a value by 1 respectively.
      E.g:
      A = 10
      A++ will give 11
      A-- will give 9

  2. Assignment Operators:
    The purpose of this operator(=) is to assign value to a variable.
    Compound assignment operators (+=, -=, *=, /=, %=) combine an arithmetic operation with assignment.

  3. Comparison Operators:
    Some common comparision operators are Equality (==, ===) and inequality (!=, !==) operators.
    Equality (==, ===) operators is used for comparing values for equality. Inequality (!=, !==) operators is used for comparing values for inequality. Relational operators (<, >, <=, >=) compare values and determine their relationship based on their magnitude.

  4. Logical Operators:
    The logical operators for boolean values are logical AND (&&), logical OR (||), and logical NOT (!).
    Short-circuit evaluation: Logical AND and OR operators exhibit short-circuit behavior, where the second operand is evaluated only if necessary.

  5. String Operators:
    The (+) string concatenation operator combines two strings.

  6. Ternary Operators:
    Conditional statements(IF/ELSE) can be quickly written using the ternary operator (condition ? expr1 : expr2).
    E.g 5 > 2 ? "yes" : "no"

  7. TypeOf Operators:
    typeof operator returns the data type of a value.
    instanceof operator tests if an object is an instance of a particular class or constructor function.

  8. Bitwise Operators:
    Bitwise operators (&, |, ^, ~, <<, >>, >>>) manipulate individual bits of numeric values.