Declaring and Using Variables

Declaring and Using Variables

Declaring and Using Variables

🙋 Need help? Ask an expert now!

When declaring a variable we specify its name (called identifier) and give it an initial value (optional). You've already encountered different variables throughout the course, so the syntax shown below should make sense:

<var | let | const> <identifier> [= <initialization>];

As we explained in the paragraph above, variables don't have to be initialized when they are declared. In the sample program above, emptyVariable is only declared but not initialized, thus printing "undefined" when it is printed to the console. The other three variables are called using var, let, and const, the three different methods used when declaring a variable.

Edit Me on GitHub!

Application Question

Consider the following code segment:

let varOne;

What does the code above print to the console?