JavaScript operators are symbols or keywords used to perform operations on variables, values, and expressions. Here are some of the commonly used JavaScript operators:
- Arithmetic Operators: These are used to perform arithmetic calculations on numeric values. The arithmetic operators include + (addition), – (subtraction), * (multiplication), / (division), % (modulus), ++ (increment), and — (decrement).
- Comparison Operators: These are used to compare values and return a Boolean value (true or false). The comparison operators include == (equal to), === (equal to and of the same type), != (not equal to), !== (not equal to or not of the same type), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).
- Logical Operators: These are used to combine multiple conditions and return a Boolean value. The logical operators include && (and), || (or), and ! (not).
- Assignment Operators: These are used to assign values to variables. The assignment operators include = (assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), /= (division assignment), and %= (modulus assignment).
- Bitwise Operators: These are used to perform bitwise operations on binary numbers. The bitwise operators include & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), and >> (right shift).
- Conditional (Ternary) Operator: This is a shorthand way of writing an if-else statement. The syntax is condition ? expression1 : expression2. If the condition is true, expression1 is executed. If the condition is false, expression2 is executed.
- Typeof Operator: This is used to check the data type of a variable or expression. The syntax is typeof variable. This will return a string indicating the data type, such as “string”, “number”, “boolean”, “undefined”, “function”, or “object”.
These are some of the most commonly used operators in JavaScript.
