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.
Iāve been stucked on this challenge for a week and my hardwork paid off and of course with the help of FCC/Help Gitter community. Thanks to @thekholm80
Lessons learned to pass this challenge:
Do not delete/modify anything inside the myLocalScope() function - you will see that there is a 'use strict' line. You need to ignore that. Before I thought that is the string value that we need to assign in the myVar variable, but itās not.
Assign value to myVar inside the myLocalScope function. You can assign either string or numeric values on it.
Lastly, read the commented out instructions on the console like / / Run and check the console AND // myVar is not defined outside of myLocalScope
The most important of all is // Now remove the console log line to pass the test Ignoring this instruction will not make you pass the challenge.
Hope this hints made you pass the challenge. Remember always Read-Search-Ask
Well, itās really easy if you follow all the Instructions and Hint Refreshing the page may help if you get stuck. Try!
Here is my spoiler (click on the blur )