Essential JavaScript

Going Further

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

  • I can declare a variable without a value

  • I can set the value of a variable after I declare it

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines