JavaScript Assignment Operators
Assignment operators put values into variables.
The plain equals sign is the main one.
There are shortcuts that change a value and save it in one step.
Simple assignment
Add and assign
Other math shortcuts
Why shortcuts help
Simple assignment
= stores the right side into the left side.
Read it as put this into that box.
Add and assign
+= means add to the old value, then save it.
It is a shorter way to write score = score + 5.
Subtract, multiply, divide
You also get -=, *=, and /=.
Each one changes the box using math, then keeps the new answer.
Remainder and power shortcuts
%= keeps the leftover. **= raises to a power and saves.
Same idea for strings
+= can also glue text onto text.
Tip: Shortcuts save typing. If a line feels unclear, write the long form first, then shorten it.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.