Explore 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 one is available in this block,…so, in the whole file and the same for this one here.…We'll cover later on what is the difference between…
Released
8/15/2018- What is variable scope?
- What are closures?
- Global vs. local variables
- Block-scoped variables
Share this video
Embed this video
Video: The different types of scope