Locked lesson.
About this lesson
How to store data in variables in JavaScript.
Exercise files
Download this lesson’s related exercise files.
Variables.docx58.6 KB Variables - Solution.docx
58.8 KB
Quick reference
Variables
Variables are used to store things.
When to use
You'll use variables ALL the time. Anytime you need to store data, you'll use variables.
Instructions
To create a variable, you need to declare it using the var keyword:
var myVariable;
To add things to variables, use the equal to sign:
myVariable = "Something";
You can declare and assign at the same time:
var myVariable = "Something";
Variable names can include letters, numbers, dollar signs, and underscores; but not dashes (-).
Hints & tips
- Variables are used to store data.
- Declare them first, then add stuff to them.
Lesson notes are only available for subscribers.