What Is a Variable?
A variable is a name that you use refer to something, such as a saved number or text. Imagine a variable as a wire that connects a name to a value.
Creating a Variable with let
One way to create a variable in JavaScript is by using the let keyword. With let, you create a "wire" that can later be reconnected to a new value. This is useful because, as you learn, you’ll see that the value your variable points to might change as your program runs.
Here’s a simple example:
let score = 10;
console.log(score);
In this code:
- We create a wire (variable) called score using let.
- We connect (or point) that wire to the value 10.
- We then print the value to the console with console.log(score).
Changing What a Variable Points To
Because the wire created with let can be reconnected, you can change its value at any time. For instance:
let greeting = "Hello";
greeting = "Hi there";
console.log(greeting); // Prints: Hi there
The wire named greeting now points to “Hi there.”
Exercises
Declaring a Variable
- Create a variable named myVariable using let.
- Set its value to "JavaScript is fun".
- Print the value using console.log(myVariable).
Changing the Value of a Variable
- Create a variable named message using let with the initial value "I love learning".
- Change the value of message to "I enjoy coding".
- Print the new value using console.log(message).


Ready to become an ethical hacker?
Start today.
As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.