javascript - And I thought I understood scope -
Can someone please tell me why the last entry of 'X' is not equal to 0 and 1. I thought because it has been declared out to be the global scope of a function and then its function is set to value 1 and this value will remain in a global form? I know that the first 'x' value inside the function is global because any variable is declared without the preferred keyword which becomes the property of the window object. Many thanks
var x = 0; // global variable function y () {x = 1; Logs ("1.% N", x); // 1 1 var x = 2; Logs ("2.% N", x); // 2 2} y (); Logs ("3.% N", x); <3> << Code>
var
subject of description Hoising , when your code is evaluated, it actually looks like this:
var x = 0; // global variable function y () {var x; // Local !! X = 1; Logs ("1.% N", x); // 1 x 1 = 2; Logs ("2.% N", x); // 2 2} y (); Logs ("3.% N", x); // 3 < Before executing y
, a new performance reference is setup, and the process before The function is executed.
This is the reason that JSLIInt has recommended only one var statement for each job, what is actually happening.
Comments
Post a Comment