In JavaScript however, functions define scope.
A variable declared outside of a function is in the global namespace. As in any language, you should try to avoid polluting the global namespace.
A variable declared inside a function is visible anywhere within that function but are not visible outside the function.
function Method1(){
var elements = [0, 1, 2, 3, 4, 5]; // available everywhere in the function
for(var i = 0; i < elements.length; i++) {
var element = elements[i]; // remember Hoisting? will be available everywhere,
//even though it was originally declared inside the loop
console.log(element);
}
}