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 Operators

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.

e.g.

condition ? expr1 : expr2

Ternary operator is frequently used as a shortcut for the if..else statements

Commonly used operators and description

JavaScript Operators

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

Arithmetic Operators

Assignment Operators

Assignment Operators

Comparison 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

e.g.

x =1 and y =2 (x < 2 & & y > 1) //Returns true

OR () : Allows you to check if one of two conditions are met

e.g.

x =1 and y =2 (x < 2 y < 2) //Returns true

NOT (!) : Allows you to check if something is not the case

e.g.

x =1 and y =2 ! (x > y) //Returns true