var lastLoopRun = 0; if (new Date().getTime() - lastLoopRun > 40) { Какое-то действие; } 

I would like to know what this line does in the if condition? Thanks in advance for the answer :)

  • This condition in the if construction means that if time is more than 40, it means that we are doing something. - And
  • checks whether the time is in milliseconds from January 1, 1970 00:00:00 minus lastLoopRun is more than 40 - Air
  • Thank you very much! - Ivan Ivanov

1 answer 1

A new instance of the Date class (read: new Date) indicates the current date and time (set on the user's computer). The getTime () method allows you to get the number of milliseconds that have elapsed since January 1, 1970 (this is called the timestamp). It turns out that in your example, the if condition checks whether the difference in the number of milliseconds that have passed since January 1, 1970, and the value of the lastLoopRun variable is greater than 40