From the course: JavaScript: Scope
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
The different types of scope - JavaScript Tutorial
From the course: JavaScript: Scope
The different types of scope
- [Instructor] In JavaScript there are a few different types of scope, local, global and block scope. We'll explore each one in depth with code examples but, in short, local scope is when a variable object or function is only available locally to a function, like the warrior2 variable. Like here. Then you have global scope. When variables, objects or functions are available to all. For example, our variable warrior1 or the function screamWarrior is defined and available in the global scope. Like this one here and the actual function here. Then you have blocks scope variables. Declare with let and const which are available within the innermost block they are surrounded by. So if we look at our current code, the warrior2 and newWarrior are block scope variables and are accessible in the block they are surrounded by. Like this one here. This one here and also this one here. This one is available in this block. This…
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.