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.

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

Operators in JavaScript can be grouped into several categories and some are follows:

  1. Arithmetic Operators:Perform mathematical calculations
  2. Assignment Operators:Assign or set values to variables
  3. Comparison Operators:Compare values
  4. Logical Operators:Logical operations like AND and OR

Arithmetic Operators

Assignment Operators

Comparison Operators

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