Variables Intro

Welcome to the first section of the course. In the next few videos we're going to explore topics of variables and data types. Two of the most important concepts in any programming language!

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of giving variables a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used through the entirety of your program.

Variables in JavaScript are containers which hold reusable data. In other words, they are units of storage, like some sort of box into which we can put data.

Here are the following three simple steps to creating a variable:

  • Create a variable with the appropriate name.
  • Store your value in it.
  • Retrieve and use the stored value from the variable.

Now, let's open our Visual Studio Code and see it in action!

The values that we store in our variables can come in the form of predefined Data Types. The computer needs to know of which type is our value so it can manipulate it properly. The lecture on Data Types is coming really soon in the course and it's going to explain all the details about them.

So, how can we create a variable? We need a var keyword, a variable name and the value we want to assign to that variable:

var variableName = 'Hello, World!';

Just a note, you're always going to see me adding semi-colons at the end of lines.

Semicolons are used to terminate a line in javascript. They are optional, but omitting them can lead to undesired consequences on rare occasions. So it's a good practice to always put them at the end!

In the next video we're going to see two more additional ways of creating variables.