Previous var declaration bad way with
a = 1 back to declare a global variable,
output 1 illustrates a = 1 does declare a global variable.
But you put elsewhere, it is not to declare global variables.
If there is a global variable outside a function which is then assigned to a
time has two functions, directly using a local variable, which is inside a fn function
if it is not currently a declare a global variable a. If there is a take advantage of this a. There is currently a below
such use is outermost var a
if there is no outside, only this time to declare a global variable
so a = 1 will declare a global variable is wrong, not only in a case of this variable under happens implicitly to declare a global variable
so a = 1 is unknown meaning
does not recommend using
such a print out a right
output under no circumstances declare a page error. Any definition of a no go use it
without being given
the code does not affect the execution of the code execution
var a lift will automatically go to the top, although it will not be executed, it will give some code illogical place, var a will chaos upgrade
second question
Do not use global variables, global variables often have problems, such as a global variable declaration, with the others I do not know.
With a wrap function. Such var a is a local variable.
Function to give him a name, by any other name, it is global variables. X is a global variable current, frank is a global variable
to var a function to place inside it is a local variable.
A function of x contained in the inside. Then x is a function of all the variables.
Anonymous function called directly, add a brace in the final surface function. But grammatical errors.
Avoid this syntax error. Then the total are included in a parenthesis inside
a function declaration, then call it immediately, this function is not only to name it. Then in parentheses there, in order not to let it report a syntax error. In order to do so many things that are not exposed to global variables
let's features will not run out, just to see curly braces will not rise up online. Where is let you write is what will not run around.
If this time will print an error in a, tips undefined.
Not to hide as a global variable, before Es6, js metamorphosis program must be used immediately to perform a function, newcomers do not understand fully
let is to facilitate the use of local variables without the need to refer to a function.
just to let the scope of braces
with var error will not.
The second feature can also let nested
This syntax is called a block, put a bunch of code in braces.
In which a new block, it is not a life with a
neither with nor with the outside of the inside of a a. Directly on the error. This is a good habit, so it will not be some strange code
second feature let's, if you are in a block inside. With no let life here is to use a variable amount. Direct'll get an error.
This feature is called Temp Dead Zone temporary dead zone
that is part of a temporary dead-checked below, in here, a can not be used, once they reported using a syntax error.
In other words, life is not called, it will direct error
const
a scope that only selected brackets.
const assigned only once chance, and then later being given the assignment to
let also again a error, can not declare a variable twice, direct error here.
js finally know to tell you when writing code is wrong here.
const of the situation. const is a constant meaning. It can only be assigned once
to sum up
Const a not defined assignment, did not run directly on the incorrect report