here are two questions about the exercise that I am doing for practicing of setInterval
fuction
- from following code, I tried to print out the variable which is self-adding by 10 within 1000 milliseconds, but when I ran it, in the console of browser, it only showed 10 times of same word "num", how do I figure it out ?
$(function() {
var timmer;
GoCount();
function GoCount() {
timmer = setInterval(function() {
var num = 0;
num += 10;
console.log(num);
}, 1000);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- and the second question is what's the difference between
setInterval
and for loop