I am trying to increment a value (in this case a UNIX timestamp, but for all we care in this case it might as well be any old integer) every 1 second, but it refuses to do so (it just stays the same).
Here’s the code
// given integer starting point
var tsmin=1332449260;
setInterval(function(){
tsmin=tsmin++;
console.info(ts);
}, 1000);
The issue comes from the difference between ++tsmin and tsmin++.
++tsmin increments the value before doing the next step, whereas tsmin++ increments the value afterwords. If you changed the line to:
it would work, because it is now incrementing before saving it as the new value. However, even though this solution ‘works’, what you really should do is:
There is no need to set tsmin if you are just incrementing like that.