This is a variable. The "let" instructs the engine to make a new variable, the "="
that we want to assign a value to it.
let beep = 'Hi';
We can also create the variable without giving it a value:
let boop;
In both cases, we can later give it a different value:
beep = 'Hello';
boop = '';
Sometimes, we want to create constant variables. Unlike the variables created above, they cannot change.
const beepBoop = 'Hello World';
This is not allowed and will throw an error. It is not allowed because we marked beepBoop
as const
.
beepBoop = 'Goodbye World';
Now that we have variables, we can use them instead of of values:
console.log(beepBoop);
<aside>
💁 In ancient times, JavaScript didn't have a concept of constant variables. Instead of let
and const
, people used the var
keyword. We don't really use it anymore, but if you still see it, think of it as let
.
</aside>