Sample Video Frame
05: Constants
Sometimes you need to create a variable that can never change. In programming this is usually called a "constant". A constant is more like a fact that should be the same value all the time. The concept of a constant is fairly new to JavaScript, so there are not too many guidelines on how to use them. I would say, use them sparingly until you figure out what works best. One place you will see them used is when you create functions in new JavaScript code.
The Code
const invincible = 94;
let changeme = 82;
console.log(`invincible=${invincible} but changeme=${changeme}`);
// this will work just fine
changeme = 100;
// uncomment this to see how you can't do it
// invincible = 100000;
console.log(`After change: invicible=${invincible} but changeme=${changeme}`);
As you can see here the keyword const is used to create a constant. This means a variable cannot change, so if you look at lines 9 and 10, you will see they are commented out (meaning disabled). You should remove the comment in front of line 10 to see thet error message you get.
Register for The Pro-Webdev Mega Bundle
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.