ES6 layman -1 new version of variable declarations:. Let and const-3 video-related interview questions

The order of execution problems

Will the value of the output is the number console.log

sure the output is 1


if there are unknown line of code will print out a few?

If this code is unknown a = 2. So in fact, console output is two

only interested in the code, code execution does not care about the order, which is the largest face questions of this trap.
The final output is

Grammar

Although i is written in the for loop inside, but it still ran out of

i is equal to 5 to be executed when i ++ then enter circulation less than inside. So when is not established within the cycle time is equal to 6, on the implementation of the bottom of the console's output





if the user clicks on this line of code is executed, then the time to go. So this line of code is the final 6.



Click the button repeatedly output results are 6


http://js.jirengu.com/?html,output



Finally, a carriage return cursor above the line of code, it generates the following Code

click navigation 3 when the output value of a few? ? ?



Code execution. The default page loaded, i was already 6 of

how to make a print out click navigation click on the navigation 2 1 2 print out of it? ? ? ?

6 has been printed out, because we have only one i

with variable j to accept variable i

print out of 5,

Why is it 5. although i ++ has been added to the 6, but has not been j ++. So i to 6 will not enter the circulation. j has the highest value of 5 is the.
Because the variable j This sucker will increase. j will increase here.


Always a i j to receive the same with the same, that is, there is only one event i and j
default value of the output i and j

let

With the let, this j will not go outside.


let's scope only the selected area of a

result output cycle Click

If you do not let, you must come up with a new scope

The new scope is generally used to perform the function immediately. This function is in the j function inside. I do not go out

that this is now a j j each cycle

that's how painful js programmer before es6 syntax yes.

You can also write, which means that the first parameter j

If i use let to modify



i scope in this piece of code is selected. So I spent the brackets are not i access the

for loop syntax to do a magic, into the circulation every time. I creates a loop in, i is equal to the value of i out.

We put out i changed to underline i, so good distinguish

this line of code is automatically added js we can not see.






A total of 7 i, a i in parentheses throughout the loop is always

and each cycle, the block will have the scope i, 0 to 5 Therefore i which is 6, is coupled with the outermost i 7 i

 

End

Guess you like

Origin www.cnblogs.com/wangjunwei/p/11746391.html