Let and Const
In JavaScript, there are different ways to declare variables. Two modern keywords you'll use are let and const. Think of these as different types of wires:
- let creates a wire that can be reconnected to different values later.
- const creates a wire that is fixed to one value and cannot be changed once set.
While you might also encounter var, it is an older way to declare variables and has quirks that can lead to errors. While it's good to know that var exists since you might encounter it, it's best to use let and const.
Using let
When you use let, you can change (reconnect) the value later. For example:
let score = 10;
score = 15;
console.log(score); // prints 15
Using const
With const, once you assign a value, the wire remains fixed—it cannot be reconnected. For example:
const birthYear = 1990;
// Attempting to reassign will cause an error:
// birthYear = 2000;
console.log(birthYear); // prints 1990
This is useful for values that should remain constant throughout your program.
When to Use let vs. const
- Use let when you know the value might change.
- Use const when the value should stay the same.
- var exists but is less predictable due to reasons not important right now. Suffice it to say that var is legacy and modern JavaScript code favors let and const.
Exercises
Reconnect the Wire with let
- Create a variable called temperature using let and set it to 25.
- Change the value of temperature to 30.
- Print the final value using console.log(temperature).
Keeping the Wire Fixed with const
- Create a constant called pi using const and set it to 3.14.
- Print the value of pi using console.log(pi).


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.