The question about JS

some time ago, I encountered such a question in the interview:


 var num=0;
 for(var i=0;i<10;iPP)
    {
        var num=1;
        num+=i;
    }
 console.log(num);
numnumconsole.lognum09
Nov.19,2021

first, the final answer should be 10;
reason:
1. The repeated declaration of variables will be ignored, but the assignment will not, so each cycle your num starts with 1
2.i < 10


is 10


this loop and var num = 0; in fact, it's in a function, and the for method itself is not a function, is it?. And try to output 10


because the code block is equivalent to a thing at the same level

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-1b35aca-2bfa6.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-1b35aca-2bfa6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?