Variable Declaration

Variables declared with var are permanent : attempting to delete them with the delete operator causes
an error.

If you attempt to read the value of an undeclared variable, JavaScript generates an error. If you assign a
value to a variable that you have not declared with var , JavaScript implicitly declares that variable for
you. Note, however, that implicitly declared variables are always created as global variables, even if they
are used within the body of a function. To prevent the creation of a global variable (or the use of an
existing global variable) when you meant to create a local variable to use within a single function, you
must always use the var statement within function bodies. It's best to use var for all variables, whether
global or local.

你可能感兴趣的:(JavaScript)