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 - JavaScript Tutorial
From the course: JavaScript Essential Training
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…
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.
Contents
-
-
-
-
-
-
-
-
Variables: Containers for everything2m 31s
-
(Locked)
Var3m 15s
-
(Locked)
Scope3m 37s
-
(Locked)
Let4m 34s
-
(Locked)
Const2m 58s
-
(Locked)
Data types3m 7s
-
(Locked)
Assignment vs. comparison4m 35s
-
(Locked)
Math operators6m 13s
-
(Locked)
Challenge intro: Calculate sales tax1m 35s
-
(Locked)
Solution: Calculate sales tax3m 30s
-
-
-
-
-
-