Why do we care about variables?
Variables are useful in two ways:
- They allow us to use the same value over and over, without having to write a string or other data type over and over.
- More importantly, we can assign variables different values that can be read and changed by the program without altering our code.
For example, a weather app can show you a different high temperature every day. Instead of writing a new website everyday, they store the information in a variable and just change the value of that variable.
We can change a variable's value if we want, like this:
var weatherCondition = 'Monday: Raining cats and dogs';
weatherCondition = 'Tuesday: Sunny';
- We created a variable by using the keyword
var and the name
- Then, we took the existing
weatherCondition variable, and set its value equal to
True to their name, variables are indeed variable.