From the course: Learning ECMAScript 6+ (ES6+)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Working with the const keyword - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
Working with the const keyword
- [Instructor] In addition to let, there's another way to create a variable with JavaScript, and that's to create a constant. So we can use the const keyword, just like we use the var keyword to create a variable that cannot be reset. But before we get to it, let's look at how we might reset the value of a variable using var. On line nine, we'll create a variable called pizza, and we'll set it equal to true. On the next line, we'll reset the value of pizza to false, and then we'll console log it. Not surprisingly, when we try to log this, it's going to reset the value of pizza to false. So by the time we hit the console message, pizza is false. Now, this makes sense in this context, but it's really a little scary. Consider this file was 100 lines long, and I didn't see that pizza's value was reset later in the file. I would just reset the value without seeing any sort of warning. This is where the const keyword comes…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.