logo

Operators

Common operators in JavaScript and how operator precedence and associativity affect expressions.

Short explanation

Operators compute values and include arithmetic, logical, comparison, and assignment operators. Operator precedence and associativity determine how complex expressions are evaluated.

Syntax example

const result = 1 + 2 * 3; // 7 due to precedence
const ok = (true && false) || true; // true

How JS handles it internally

The parser builds an AST reflecting operator precedence, then the evaluator executes nodes accordingly. Understanding precedence helps you write expressions without unnecessary parentheses.

FAQ

Q: How do I remember precedence?

A: Evaluate common cases and use parentheses to make intent explicit; rely on linters for clarity.