Local Scope and Functions
Problem Explanation
Local scope means that the variable is available within a certain area. In the case of this exercise, myVar
is only available within the function, and not anywhere outside.
Solutions
Solution 1 (Click to Show/Hide)
function myLocalScope() {
// Only change code below this line
var myVar;
console.log('inside myLocalScope', myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log('outside myLocalScope', myVar);
Code Explanation
- The variable only exists in the function. Outside the function, it is non-existent.