Tell us what’s happening:
I pass the test, although I shouldn’t. Is this a bug?
console sees the variable
although in theory it should not
sorry for noob question:( Your code so far
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/78.0.3904.70 Safari/537.36.
I would say there’s an error, because myVar is actually logged twice. Besides, the instructions say:
Run the tests and then follow the instructions commented out in the editor
Where one of the comments say that, to pass the test:
…remove the console log line
Now, ignoring this possible error, You’re right, a variable defined inside a function cannot be read from outside, and this error is shown when using the developer tools (press F12 or Control + Shift + I on the test page).
Thank you! I didn’t think that the variable from the function could register twice, and I thought that I could misunderstand the lesson. Thank you again!
myVar is undefined in global scope (typeof check). Won’t fail if you also declare myVar outside the function, only if you initialize it with a value.
The function is set up correctly (regex).
So I’m not really sure why the code comment says that. All you need to pass the tests is this.
function myLocalScope() {
var myVar;
}
I think the output is coming from the setup and teardown, but I don’t really know much about that part of the tests. I’m not sure it is working as intended. You can check it out here it has the solution but in this case, that isn’t much of a spoiler.
Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.