Why does this code output 0? I feel like setInterval () has been skipped. I'm so confused. Solve

after this code is executed, the console outputs 0 directly without first executing the anonymous function
in setInterval (). The code is as follows:

        var div = document.getElementById("div");
        div.onclick = function() {
            var i = 0;
            var timer = null;
            timer = setInterval(function() {
                iPP;
                console.log(i)
                if(i == 10) {
                    clearInterval(timer);
                }
            },300);
            if(i == 0) {
                clearInterval(timer);
                console.log(i);
            }
        }

clipboard.png
is inexplicable! Ask the great god to solve the doubt

May.15,2021

the delay operation is added to the task / asynchronous queue and is performed when the main line is finished.


you set the timing function to execute in 300ms. Do you feel that walking this section will be slower than 300ms? It must be output first and then wait for the timer to trigger


asynchronously understand


Why do you think the code in settimeout should be executed first?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9605d-159e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9605d-159e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?