JavaScript Operators - special symbols that perform unique operations on one or more operands (data value).
Different JavaScript Operators:
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Conditional Operators
Ternary Operators
Arithmetic Operators - are used to perform mathematical operations between numeric operands such as addition, subtraction, multiplication, and division among others.
Assignment Operators - used to assign values to a variable. The most basic operator is the equals sign (=). This is used to assign the value on the right to the variable on the left.
Unary Operators - is an operator that operates on only one operand. They are used to perform various operations such as incrementing/decrementing a value, negating an expression, or inverting the value of a Boolean.
Increment (++) - this operator increases the value of a variable by one.
Decrement (--) - this operator decreases the value of a variable by one.
Pre-Increment/Decrement - when the operator is placed before the variable (e.g., ++x or --x).
Post-Increment/Decrement - when the operator is placed after the variable (e.g., x++ or x--).
Comparison Operators - used to compare two values and return a Boolean value (true or false). They are used in logical statements to determine equality or difference between variables or values.
Equal to (==) - checks if the values of two operands are equal, ignoring the type of the operands.
Strictly equal to (===) - checks if the values and the types of two operands are equal.
Notequal to (!=) - checks if two operands are not equal, again ignoring the type.
Strictly not equal to (!==) - checks if two operands are not equal in value or type.
Greater than (>) - checks if the value on the left is greater than the value on the right.
Lessthan (<) - checks if the value on the left is less than the value on the right.
Greater than or equal to (>=) - checks if the value on the left is greater than or equal to the value on the right.
Less thanorequalto (<=) - checks if the value on the left is less than or equal to the value on the right.
Logical Operators - used to determine the logic between variables or values. They are used to combine two or more conditions and return a single true/false result. This is useful for creating more complex conditions in our programs.
LogicalAND (&&) - true only if both expression1 and expression2 are true.
Logical OR (||) - true if either expression1 or expression2 is true.
Logical NOT (!) - false if expression is true and vice versa.
Conditional Operators (Ternary) - can be used to replace an if ... else statement in certain situations.
variable name = (condition) ? value1 : value2
Nested Ternary Operators - you can also nest one ternary operator as an expression inside another ternary operator.