Course contentsShow
← JavaScript
Lesson 269 of 2,7237. Arithmetic and OperatorsFree lesson

Assignment Has Lowest Precedence

Why assignment operators evaluate last, allowing patterns like `x = y = z = 0` to work right-to-left.

Assignment Has Lowest Precedence

What you'll learn: Why assignment operators always evaluate last, allowing you to chain assignments and build complex expressions safely.


The Core Idea

In JavaScript's order of operations, assignment operators (like =, +=, -=) have the lowest precedence of almost all operators. This means everything else in an expression gets calculated first, and then the final result gets assigned to the variable.

Think of assignment like the final step of wrapping a gift: you gather all the materials, fold the paper, add the ribbon, and only then do you hand the finished package to someone. Assignment is that last "handoff."

Why This Matters

Because assignment happens last, you can write expressions like this:

let x = 5 + 3 * 2;

Here's what happens in order:

  1. 3 * 2 evaluates to 6 (multiplication has higher precedence)
  2. 5 + 6 evaluates to 11 (addition happens next)
  3. 11 is assigned to x (assignment happens last)

Right-to-Left Assignment Chains

This low precedence also enables chaining assignments:

let x, y, z;
x = y = z = 0;

Because assignment evaluates right-to-left and returns the assigned value, this works like:

  1. z = 0 (z becomes 0, expression returns 0)
  2. y = 0 (y becomes 0, expression returns 0)
  3. x = 0 (x becomes 0)

All three variables end up with the value 0.


Key Takeaway: Assignment operators have the lowest precedence, so they always happen after calculations are complete. This lets you write clean expressions and chain multiple assignments together.