function myLocalScope() {
'use strict'; // you shouldn't need to edit this line
var myVar =5;
console.log(myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
// Now remove the console log line to pass the test
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36.
I think something about the curriculum update made the console a bit weird. It seems to print things more than once now when it didn’t do that before. So I think it just looks like myVar is printing the second time in the code.
But if you change that second console.log line to something different like console.log(myVar + 1) which should print 6, you will see that the console still just has 5 and 5. So it’s just the one inside the function that is printing.
The variable myVar is not actually accessible outside the function. It’s passing the test even though you didn’t delete the console.log. The test window is not showing the error that shows up in a real console. If you open your browser’s console (F12) you will see what happens when you try to console.log(myVar) outside of the function:
Thank you for the F12! It’s a surprise for me that the real console and freecodecamp console are different.
I get somewhat different console outputs in the next task on global/function scopes:
You don’t actually have to copy-paste the function into the console if you don’t want to. You can click the “Run All Tests” button in freeCodeCamp and observe your browser’s console.
Cool, thank you!
Hitting “Run the Test” reproduced FCC console output. It seems one time isn’t just good enough not the evaluator I’m not sure how it works, I just hope it will make sense sometime.