In the following code, shouldn't x be considered a global variable? Thus, when it gets to the console.log line x it should have the value of "World". However, when I run this code it logs "Hello undefined". `
let x = "World";
function sayHello(x) {
console.log("Hello ", x);
}
sayHello();
But when I change the parameter to y, it then works as I expected, logging "Hello World.
let x = "World";
function sayHello(y) {
console.log("Hello ", x);
}
sayHello();
Can someone explain what is going on here?
thanks