Operators

What is an Operator?

🙋 Need help? Ask an expert now!

An operator is a symbol that represents an operation performed over data at runtime. Operators take one or more arguments (called operands) and produces a new value. Operators have precedence (priority), a system that defines which operator will be evaluated before the other. The parenthesis operator always has highest precedence, so it's considered good practice to use parentheses, even when it's not necessary to improve code readability. You can always take a look at the MDN Precedence chart if you're confused about the precedence of two operators.

Operators in JavaScript are either unary (take one operand), binary (takes two operands), or ternary (takes three operands). Except for the assignment operators, all binary operators are left-associative, meaning the expression is evaluated from left to rights. The assignment operators and the conditional operator (?:) are right-associative. Below are the operators by categories in JavaScript:

  • Arithmetic (+, -, *, /, %, ++, --)
  • Logical (&&, ||, ^, !)
  • Binary (&, &#124;, ^, ~, <<, >>, >>>)
  • Comparison (==, !=, <, >, <=, >=, ===, !==)
  • Assignment (=, +=, -=, *=, /=, %=, &#124;=, ^=, <<=, >>=)
  • Concatenation (+)
  • Other (., [], (), ?:, new, in, typeof, instanceof, ...)
Edit Me on GitHub!

Application Question

Which operator has the highest precedence?