What is a variable?
In programming a variable is used to store some form of data. We can assign a name to a variable and then assign a value to it.
A variable can have the following values assigned to it:
- String - Simply a set of characters, such as a sentence or word.
- Boolean - True, or false.
- Null - Basically, meaning nothing. No value.
Lets see an example of a variable declaration:
//Variable with numeric value:
// Variable with string value:
// Variable with boolean value:
// Variable with null value:
So what use are variables?
Using operators we can do all kinds of things with our variables. This includes addition, subtraction, multiplication,division and more!
You can read more about this in the operators section.
Things to remember
- You can actually declare a variable without assigning a value to it.
- The value of a variable can change throughout the execution of a script.