Does setTimeout in JavaScript accept real (floating point) delay times_

我怕爱的太早我们不能终老 提交于 2019-12-23 17:34:02

问题


I was just looking at JavaScript Timing Events, and there it says that "The second parameter indicates how many milliseconds from now you want to execute the first parameter."

Now, I know that in JavaScript, both floating point and integers are of type Number, and so syntactically I can enter a floating point value, e.g. 'setTimeout("javascript statement",4.5);' - however, will JavaScript even attempt to create a delay of 4.5 milliseconds there; or will it just automatically truncate to integer and go on?

Thanks in advance for any answers,
Cheers!


回答1:


This is almost certainly browser-dependent (I haven't checked it's not part of the language spec), but typically this value is stored in a 32-bit signed int, so would only accept integer values between 0 and 2^31 - 1.

Related:

  • Why does setTimeout() "break" for large millisecond delay values?
  • 7.3 Timers — HTML Standard


来源:https://stackoverflow.com/questions/7286178/does-settimeout-in-javascript-accept-real-floating-point-delay-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!