Global variables are declared outside of a function for accessibility throughout the program, while local variables are stored within a function using `var` for use only within that function's [scope](https://developer.mozilla.org/en-US/docs/Glossary/Scope). If you declare a variable without using `var`, even if it's inside a function, it will still be seen as global:
*<ahref='http://www.w3.org/wiki/JavaScript_best_practices#Avoid_globals'target='_blank'rel='nofollow'>JavaScript Best Practices: Avoid Globals</a>
* [What's the difference between a global var and a window.variable in javascript?](https://stackoverflow.com/questions/6349232/whats-the-difference-between-a-global-var-and-a-window-variable-in-javascript)
---
The scope of JavaScript variables are either global or local.
Global variables are declared OUTSIDE the function and its value is accessible/changeable throughout the program.
You should ALWAYS use **var** to declare your variables (to make locally) else it will install GLOBALLY
Take care with the global variables because they are risky. Most of the time you should use closures to declare your variables.
Example:
```javascript
(function(){
var myVar = true;
})();
```
#### More Information:
- [JavaScript Best Practices: Avoid Globals](http://www.w3.org/wiki/JavaScript_best_practices#Avoid_globals)
- [Global Variables are bad](http://c2.com/cgi/wiki?GlobalVariablesAreBad)
- [MDN - Global Variables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var)