1. Variables defined with var within the scope of the function are local variables, which are defined as global variables without var.
Using the VAR definition
var a = ' Hello World ';
function bb () {
var a = ' Hello Bill ';
Console.log (a);
}
BB ()//' Hello Bill '
Console.log (a); ' Hello World '
Do not use VAR definitions
var e = ' Hello World ';
function cc () {
e = ' Hello Bill ';
Console.log (e); ' Hello Bill '
}
CC ()//' Hello Bill '
Console.log (e)//' Hello Bill '
2. Under global scope, variables defined with Var cannot be deleted, and variables with no Var defined can delete. It also implies that the global variable is strictly not a real variable, but rather a property of the global object, because the property can be removed by the delete and the variable is not available.
3. Using var to define variables also promotes variable declarations, which are
Use Var to define:
function hh () {
Console.log (a);
var a = ' Hello World ';
}
HH ()//undefined
Do not use VAR definitions:
function hh () {
Console.log (a);
A = ' Hello World ';
}
HH ()//' A is not defined '
This is the declaration of variables defined using VAR in advance.
4. In ES5 ' use strict ' mode, if the variable is not defined with VAR, it will be an error.
JavaScript variable declaration has the difference between Var and no Var