Thanks a lot in advance for helping me out!
var f2 = function() {
x = "inside f2";
};
f2();
console.log(x);
// → inside f2
Why do I get the x as a global variable with value "inside f2" when I didn't declare it to be a global variable with "var x;" before defining the function?
var f2 = function() {
var x = "inside f2";
};
f2();
console.log(x);
// → Uncaught ReferenceError: x is not defined
Am I right in assuming that x is not defined in this case because there is no global variable x, only the local variable x within the function f2?