var
creates a variable for the current scope. So if you do it in a function, it won't be accessible outside of it.
function foo() {
var a = "bar";
window.b = "bar";
}
foo();
alert(typeof a); //undefined
alert(typeof b); //string
alert(this == window); //true