Para este fragmento, no me sorprende variable global 'a' evalúa a ser 5.Intrigado por este fragmento de código JavaScript
http://jsfiddle.net/MeiJsVa23/gZSxY/:
var a = 10;
function func(){
a = 5;
}
func(); // expect global variable 'a' to be modified to 5;
alert(a); // and this prints out 5 as expected. No surprise here.
Pero ¿cómo es que para este fragmento de código, global variable 'a' evalúa ser 10 y no 5? Es como si el a = 5
nunca sucedió.
http://jsfiddle.net/MeiJsVa23/2WZ7w/:
var a = 10;
function func(){
a = 5;
var a = 23;
}
func(); // expect global variable 'a' to be modified to 5;
alert(a); // but this prints out 10!! why?
Guau, creo que su pregunta ha sido respondida;) – mplungjan