Essential JavaScript

Empty Variables

Earlier, we declared a variable with a value like this.

var x = 10;

We can also declare a variable without assigning a value.

Try running this in the editor:

var x;
console.log(x);

In this case, the value of the variable is undefined.

Now try this:

var x = 5;
console.log(x);

This time we see 5 because that is the value of x.

Assigning Empty Variables

If we declare a variable without a value, we can still assign it a value later:

var x;
x = 9;
console.log(x);

Learning Goals

Code Editor