⬅️ Assignment
5th Grade 💻 Coding
Assignment is the action that puts a value into a variable. In Python and JavaScript you do it with a single equals sign: `x = 5`.
In an assignment, the computer first works out whatever is to the right of the = sign, and only then puts the result into the variable on the left. That’s why x = x + 1 makes perfect sense: the computer reads the current value of x, adds 1 and stores the result back in x. In math that would be an equation with no solution — in programming it’s an action.
An assignment wipes out the old value: after x = 5 and then x = 8, x holds only 8. That’s the difference from the comparison sign ==, which asks “Are these equal?” and doesn’t change anything. In JavaScript, you also write let the first time you assign a variable.
For example
name = "Ava"puts the text “Ava” into the variablename.- After
a = 3anda = a * 2, the value ofais 6.
📌 Remember: Assignment: work out the right side first, then store it on the left.
Quick quiz
What does an assignment do?
If x = 4 and then x = x + 1, what is x?
What happens to the old value when you assign a new one?