My Journey to Learning Javascript: Notes- Variables





Variables can be thought of as containers. You can place data into these containers and then refer to the data simply by naming the container. First you must declared the variable with var.

var myName;


Variables may not contain reserved words that javascript uses such as var, debugger, function and so on. They may also not contain certain characters such & and %. They may include numbers but they cannot begin with them. Also the first letter of the first word must be lowercase and the first letter of the second word must be CAPATALIZED.


Acceptable:

var myName;
var myName99;
var myFirst_Name:


Not Acceptable:


var function;
var 9myName;
var %myName;
var myName%;


It is a good practice to give variables descriptive names. For example a variable for a person’s first name could be var firstName.


Data can be assigned to variables using the equals sign, = . Variables must end with a semicolon to indicate the end of the statement. Strings, numbers, booleans and even other variables can be assigned to them.