📄️ What are Operators?
Operators are symbols that perform operations on operands. In JavaScript, operators are used to perform arithmetic, comparison, logical, assignment, bitwise, and other operations. They are classified into different categories based on their functionality.
📄️ Arithmetic Operators
Arithmetic operators are used to perform mathematical operations on numbers. JavaScript provides several arithmetic operators that allow you to add, subtract, multiply, and divide numbers. You can also use the modulus operator to find the remainder of a division operation and the exponentiation operator to raise a number to a power.
📄️ Assignment Operators
In JavaScript, assignment operators are used to assign values to variables. They allow you to update the value of a variable based on its current value or the value of another variable. Assignment operators combine the assignment (=) operator with another operator to perform an operation and assign the result to a variable.
📄️ Comparison Operators
These operators are used to compare two values and return a boolean result(True or False). They are commonly used in conditional statements to determine the flow of a program based on the comparison result.
📄️ Conditional (Ternary) Operator
Ternary operators is also known as the conditional operator. It is a shorthand way of writing an if...else statement in a single line. The ternary operator takes three operands), and an expression to execute, if the condition is false.
📄️ Logical Operators
Logical operators are used to combine or invert boolean values. They are commonly used in conditional statements to determine the flow of a program based on multiple conditions. JavaScript provides three logical operators: && (logical AND), || (logical OR), and ! (logical NOT). Javascript allows you to use the logical operators on Boolean values and non-Boolean values.
📄️ Bitwise Operators
Bitwise operators are used to perform bitwise operations on binary numbers. These operators treat their operands as a sequence of bits and perform operations on each pair of corresponding bits. JavaScript provides several bitwise operators that allow you to perform bitwise AND, OR, XOR, NOT, left shift, and right shift operations.
📄️ Operator Precedence
Operator precedence determines the order in which operators are evaluated in an expression. JavaScript follows a set of rules to determine the precedence of operators. When multiple operators are used in an expression, JavaScript evaluates them based on their precedence level. If two operators have the same precedence level, the associativity of the operators determines the order of evaluation.