6

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!

sdaau
  • 36,975
  • 46
  • 198
  • 278
  • 2
    http://aspektas.com/blog/w3fools-a-foolish-attack-on-w3schoolscom/ - squabbling over tedious tidbits on a third-party website is the least helpful thing you could possibly post here. – Chris Baker Sep 02 '11 at 16:08
  • Thanks for that @Neal - neat page; however, my question is more related to how JavaScript interprets the timeout argument, instead of being related to actual syntax for a command - hence, the only `setTimeout` comment there: "*You never pass a string to setTimeout() unless you like using eval()*" is not really related to this question. Still, a good page to know ;) Cheers! – sdaau Sep 02 '11 at 16:11
  • 3
    I contend that it is **not** a good page to know. Unlike w3schools, w3fools contains no actual information of any kind. A **good** page to know is https://developer.mozilla.org/en/window.setTimeout. w3Fools is a waste of everyone's time. – Chris Baker Sep 02 '11 at 16:13
  • 1
    Perhaps this is a more constructive suggestion: try using MDN (aka MDC) for JavaScript reference: https://developer.mozilla.org/en/window.setTimeout – Matt Ball Sep 02 '11 at 16:13
  • Cheers @Chris and Matt Ball (ehm, only one user can be notified :) ) - great pages to have around.. – sdaau Sep 02 '11 at 16:18

1 Answers1

2

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:

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Thank for that @Matt Ball - my question is slightly different, I guess. If JavaScript stores the timeout argument as "millisecond" and integer, then "4.5" millisecond would, I guess, be truncated to 4, and JavaScript would go along with that. However - I don't know this, but maybe it's possible - if JavaScript converts internally that argument to microseconds, in that case "4500" micros, even as an integer, still would describe the same as 4.5 millis. Would you happen to know the specifics of that? Thanks - and cheers! – sdaau Sep 02 '11 at 16:15
  • Like I said: **it's going to depend on the browser implementation.** Still, I strongly doubt that there is any browser which actually tries to handle non-integer delay values by converting them to finer-resolution units, especially because [the callback might actually fire later](https://developer.mozilla.org/en/window.setTimeout#Minimum_delay_and_timeout_nesting). **TL;DR** I think you're overthinking this/worrying too much about it. – Matt Ball Sep 02 '11 at 16:18
  • Awesome, @Matt Ball - many thanks for that, that is exactly the kind of information I was looking for. Cheers! – sdaau Sep 02 '11 at 16:19