javascript - Problem with variable assignment in timer
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:34:41
0
1
525
var a=0;
var timer=setTimeout(function(){
    a++;
},1000);
if(a>0){
    alert("1");
}

I clearly changed the value of a in this code in the timer, why is the output still 0?
How should I write to make this pop-up window pop up? (Based on making the judgment effective. )

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
伊谢尔伦

The execution sequence you imagined

var a = 0;
a++;
console.log(a);

Actual execution sequence

var a = 0;
console.log(a);
delay 1 second ……
a++;

There are many ways to get this a=1, but you don’t know the meaning here, what is it for.

If you have additional questions, please put them in the question, not in the comments of the question.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template