An operator in JavaScript is a standalone piece of syntax that forms an expression and is typically used to derive something or compute a logical or mathematical output from a set of inputs (called operands).
Here, we can see an expression containing an operator (+) with two operands (3 and 5):
3 + 5
Any operator can be said to have four characteristics:
- Its arity: how many operands the operator accepts
- Its function: what the operator does with its operands and what it evaluates to
- Its precedence: how the operator will be grouped when used in combination with other operators
- Its associativity: how the operator will behave when neighbored with operators of the same precedence
It's important to understand these foundational characteristics as it will vastly aid your usage of operators in JavaScript.