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.
What is scope in JavaScript? - JavaScript Tutorial
From the course: JavaScript: Scope
What is scope in JavaScript?
- [Instructor] For some, JavaScript's code can be a bit intimidating but it's very simple. Put in its simplest terms, scope determines accessibility or visibility of the variable. Depending where and what type of scope we are using it will determine if your variable is available when you call it. Let's type some code to visualize what scope is. Let's remove the console log here and let's add a warrior, so var warrior = Ninja. Then let's create a function. We'll create a function with a const this time, and we'll call this one screamWarrior and we won't take any parameters. Inside of that function, we'll define another variable, warrior2 = Samurai. Then inside of the function, we'll console.log warrior and warrior2 and outside of the function definition we'll run the function and then we'll console.log the warrior1 or the warrior and warrior2 and you can save this. When you look into this code here, you have the warrior…
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.