Menu
Coddy logo textTech

Empty Variables

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 9 of 77.

In JavaScript, it's possible to declare variables without assigning them a specific value. This can be useful when you know you'll use a variable later in your code, but you don't yet know its initial value.

To declare an empty variable in JavaScript, you can use the let keyword followed by the variable name, without assigning any value:

let myVariable;

This creates a variable named myVariable but doesn't assign any value to it. The variable is said to be uninitialized.

When you try to access an uninitialized variable, it will have a special value called undefined:

console.log(myVariable); // Output: undefined

You can assign a value to an uninitialized variable later in your code using the assignment operator =:

myVariable = 10;
console.log(myVariable); // Output: 10
challenge icon

Challenge

Beginner

Declare two empty variables named a and b.

Cheat sheet

To declare an empty variable in JavaScript, use the let keyword followed by the variable name:

let myVariable;

Uninitialized variables have the value undefined:

console.log(myVariable); // Output: undefined

You can assign a value to an uninitialized variable later using the assignment operator =:

myVariable = 10;
console.log(myVariable); // Output: 10

Try it yourself

// Type your code below


// Don't change the line below
console.log(`a = ${a}, b = ${b}`)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals