Tell us what’s happening:
I tried to add another Automatically Global in this task.
Let say I’ll have carName = "Volvo";
under fun1()
or fun2()
it won’t work.
I got “ReferenceError: carName is not defined” in the console.
But if I have new Automatically Global in the new function:
function fun3() {
carName = "Volvo"
}
it works. Is it limitation from JavaScript or limitation from this tool?
Your code so far
const myGlobal = 10;
function fun3() {
// carName = "Volvo" // it works here
}
function fun1() {
oopsGlobal = 5;
// carName = "Volvo" // it won't work here
}
function fun2() {
// carName = "Volvo" // it won't work here
let output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Global Scope and Functions
Link to the challenge: