I wrote this code to teach myself about JavaScript closures:
function1 = function(){
var variable = \"foo\"
var function2 = function(argument){
conso
Variables live in the scope where they are declared, which is either global or a function.
The keyword here is scope.
As explained brilliantly in the MSDN website:
A variable that is declared inside a function definition is local. It is created and destroyed every time the function is executed, and it cannot be accessed by any code outside the function. JavaScript does not support block scope (in which a set of braces {. . .} defines a new scope), except in the special case of block-scoped variables.
EDIT:
It is actually a little more complicated than this, see toddmotto's post about JS scopes.