+ 1
How can i make a number add +1 every millisecond with javascript
eg..- 0+1,+1+1+1+1+1
2 Respuestas
+ 5
Actually processing the addition of 1 to a number every millisecond consistently and accurately is most likely not going to happen as there will be loss due to the time it takes to process the calculations. You may be better using Date.getTime() to set a variable to the current time then use a loop (or not, depending) to set another variable to the difference between the next call to getTime() and the original call. This will effectively give you the count in milliseconds of time passed between calls with much less loss in accuracy due to processing, since each new call will account for that loss. You could also use a starting number held as an offset and then add/subtract the offset from the result to get your end number.
https://www.w3schools.com/jsref/jsref_gettime.asp
0
Yes you can
use setInterval() Method
syntax:
setInterval(functionName , 1000); //in miliseconds
ex ->
let a = 0;
setInterval(function(){
console.log(`The value is : ${a}`);
a += 10;
}, 1 * 1000);
//set interval will run continuous infinitely