Question: In Javascript, if I declare variables with var in javascript outside of a function

```
var foo = 1;
var bar = 2;

function someFunction() {
    ....
}

```

are those variables within the scope of the document or the window? Furthermore, why does this matter? I know that if one declares a variable without var, then the variable is global.

Is there a simple way for me to test whether a variable falls within the scope of the document or the window?

Answer: 
`var` limits the scope of a variable to the function it was defined in, so variables defined at the top level with `var` will effectively have global scope.

If you assign a value to a variable that hasn't been scoped with `var` then it becomes global regardless of where you define it.

There is a good article on javascript scopes here: [What is the scope of variables in JavaScript?](https://stackoverflow.com/questions/500431/javascript-variable-scope)
as JavaScript has only function scope, variables defined by the `var` keyword are scoped to the containing function.

you can easily check for global scoping by opening the JavaScript console in the browser (or directly in your code), and typing:

```
varRef && console.log(varRef)

```