I just ran into this by chance when demonstrating variable scoping in this repl. Take this code for example:
var myFunc = function() {
var name = 'Matt';
var functionScopedVariable = "I'm in the function"
console.log(name); // => 'Matt'
console.log(functionScopedVariable); // => "I'm in the function"
}
myFunc();
console.log(name) // => ''
console.log(typeof name) // => string
console.log(functionScopedVariable) // => ReferenceError: functionScopedVariable is not defined
I thought this might be some weird namespacing with repl, however go to any website, open up your console, and type name and it'll output "" instead of ReferenceError: name is not defined. What is going on here? It's not breaking anything, just super curious. I've googled around a bit but I can't seem to find anything on this topic.
windowhas anameproperty - this isn't a "javascript" default as such (e.g. nodejs does not have a globalnameproperty), this is to do with HTML/DOM - for instance, you also have things likeImageas a global, nothing to do with the javascript language though