From the course: JavaScript Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Const

Const - JavaScript Tutorial

From the course: JavaScript Essential Training

Start my 1-month free trial

Const

- [Instructor] The const statement defines a block scoped constant. From a scope perspective it works the same as the let statement, but a const is a constant meaning once it's defined, you cannot assign a new value to it. Let's look at our example again to see how this works here. Here we have our example in the status it was when we left it in the previous movie. Jumping over into the code, you can see we're now using lets instead of are so that we ensure that there is block scope and everything is working properly. But we still have this redefinition of a value down here. We redefined the color value to sky blue. Now let's see what happens if I change the lets at the top here to a const. Save. Check in the browser. And once again we have that problem where the right-hand box turns green. Only this time, the title is also black. So what is going on? Looking at the console we get a new Uncaught TypeError…

Contents