When defining variables in JS, we are used to using Var, in fact, omitting Var can also be used.
To summarize today, use Var or omit Var to define the difference between variables 1, var private variable, can only be used in the current JS, or in the current scope to use, define private variables, can not delete;2, omit var definition variables, such as a = "SSS", defined a global variable object A, A is not deleted before the delete, we can directly in the browser console input A can see the results, in any one JS can call this object, you can choose Delete. It is not recommended to omit Var, omit Var when you have to carefully omit Var will bring the following: 1. The semantics are not clear. 2. When the team develops, it is easy to overwrite variables in other scopes and throw exceptions. 3. Add unnecessary members to the Window object, that is, to bring unnecessary pollution to the window, so use the best by the way delete, so as not to affect other variables
The difference between using Var and omitting Var to define variables in JS