variables
In this module we'll study variables.
Description
Think of a variable as a container. Cup analogies work really well with understanding variables. They store info. We can pour liquid into a cup and change it's value. We can pour two half cups into another cup. We can pour one cup into a bigger cup and then put it into an array of cups.
File Location
You should be located in the following file:
Description
Variables are used to store values. They are containers for values. That's it. Let's keep it that simple for now.
Declarations
First, they must be declared:
The name could be anything you want. You could name it spaghetti
or football
.
Initialized
Then, variables must be initalized:
Initialization is used for stating what the value of that variable is holding, as well as its type. (More on types later).
Declarations and Initializations
You can also do it all in one statement:
Variables Demo
Variables Demo
Assignment
It is common to assign a value to a variable. Then use that variable to stand for that think: Consider the following:
Naming
We can name variables anything we want. This means that there is room for creative writing in software:
The variables should be sensibly named though, and able to be understood by fellow developers.
Camel Casing
Variable names, in most cases, should be camel cased. This means that the first word is lower case and each consecutive word is upper case. It has humps like a camel. Consider the following examples:
Think it Through
Think through the answer for each one of the problems below:
A FEW DON'TS
You can't start a variable with a number:
Reserved Words
There are exceptions for naming variables. The following list is a group of reserved words in JavaScript, and they should not be used as variable names:
Last updated