Variables have either a global scope or a local scope.
Source Code
var globalVar = "I'm global";
function testScope() {
var localVar = "I'm local";
console.log(globalVar); // Accessible here
console.log(localVar); // Also accessible here
}
testScope();
console.log(localVar); // Error: localVar is not defined outside the function