From the course: JavaScript Essential Training

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Let

Let

- [Instructor] The let statement defines a block-scoped local variable, meaning it's only defined within its currently-enclosed block. This allows us to safely avoid that variable scope issue we covered in the previous movie. In the exercise files for this movie, we still have the same scope problem. The right box is the same blue as the title and that's not what we want. This is the scope problem. Now I can use let to solve my scoping issue. And I do that by declaring a new variable inside the function scope using let. Save this, go back in the browser. And now we have the correct colors. Looking at this, you may be wondering, How can I do this? I'm effectively creating two variables with the same name. We have var color and then we have let color down here. The reason is we're now working inside a local scope of just this function, and inside this function, we can now declare all new variables using let and they…

Contents