A curious bit of code is here ...
var x = 5; function fn() { x = 10; return; function x() {} } fn(); alert(x);
Here jsFiddle
Is it function x() {}called at all after return? Why not warn 10?
function x() {}
return
function x() {} raised to the beginning of the field fn, and this actually makes the xlocal variable before x = 10;evaluated.
fn
x
x = 10;
Function not set to 10.
10
: . x 10. var , , , x, 10.
var
MDN ( ):
::var,"" , vars-redeclarations no-ops
:
x float , 10
x fn; x. , ββ x. , , x 10, x 10.
5:
var x = 5; function fn() { x = 10; return; var x; } fn(); alert(x);β
, x. return - - .
, 10, x .
, JavaScript. , . ( ).
, :
var x = 5; function fn() { var x; x = function () {} x = 10; return; } fn(); alert(x);
x , , x, .
, fn , x . .
X fn() - x - var
x() {}, x 10