JavaScript Operators
JavaScript has a number of operators that you can perform operations on expressions. The symbol is used in an expression with either one or two values to perform an operation, and return a result value. The expressions that the operators operate on are called operands.
![](https://www.corelangs.com/wp-content/uploads/2024/05/js-1.png)
JavaScript supports unary operators, binary operators and one ternary operator to manipulate the data in your programs. Operators that work on only one value are called unary operators. Ex: increment operator (++). Binary operators that require two expressions to perform an operation. Ex. most mathematical operators are binary operators (+ Addition). Ternary operator, which requires three expressions to manipulate the data in your programs.
example
condition ? expr1 : expr2
Ternary operator is frequently used as a shortcut for the if..else statements
Commonly used operators and description
![](https://www.corelangs.com/wp-content/uploads/2024/05/operators.png)
Operators in JavaScript can be grouped into several categories and some are follows:
- Arithmetic Operators:Perform mathematical calculations
- Assignment Operators:Assign or set values to variables
- Comparison Operators:Compare values
- Logical Operators:Logical operations like AND and OR
Arithmetic Operators
![](https://www.corelangs.com/wp-content/uploads/2024/05/arithmetic.png)
Assignment Operators
![](https://www.corelangs.com/wp-content/uploads/2024/05/assignment.png)
Comparison Operators
![](https://www.corelangs.com/wp-content/uploads/2024/05/comparison.png)
Logical Operators
And (&&), OR () and NOT (!) are Javascript logical operators and they return a Boolean value.
AND (&&) : Allows you to check if both of two conditions are met
example
x =1 and y =2
(x < 2 & & y > 1) //Returns true
OR () : Allows you to check if one of two conditions are met
example
x =1 and y =2
(x < 2 y < 2) //Returns true
NOT (!) : Allows you to check if something is not the case
example
x =1 and y =2
! (x > y) //Returns true