Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hex in jquery's setInterval() and setTimeout()

I am making a script that checks to see if a server is connected or has gone away.While looking around how others have done it,i realized that some are using hex inside the function.For instance setInterval(l,6E4)

Another example

setTimeout(function(){d(window.checknet.config.checkURL)},window.checknet.config.checkInterval)}a=a||{};a.checkURL=a.checkURL||window.location.href;a.checkInterval=a.checkInterval||5E3;a.warnMsg=a.msg||"No Internet connection detected, disabled features will be re-enabled when a connection is detected. ";

This is the use of hex a.checkInterval=a.checkInterval||5E3;

Why is hex being used instead of ordinary decimal figures?.

like image 816
You Know Nothing Jon Snow Avatar asked Jan 22 '14 08:01

You Know Nothing Jon Snow


People also ask

What is the difference between setTimeout () and setInterval ()?

setTimeout allows us to run a function once after the interval of time. setInterval allows us to run a function repeatedly, starting after the interval of time, then repeating continuously at that interval.

Which is better setTimeout or setInterval?

The only difference is , setTimeout() triggers the expression only once while setInterval() keeps triggering expression regularly after the given interval of time. (unless you tell it to stop). To stop further calls, we should call clearInterval(timerId) .

What is setTimeout and setInterval in JavaScript?

setTimeout(function, milliseconds ) Executes a function, after waiting a specified number of milliseconds. setInterval(function, milliseconds ) Same as setTimeout(), but repeats the execution of the function continuously.


1 Answers

That is not hex, its a number written in Scientific Notation, 6 x 104.

= 60.000

As the time of setInterval is in milliseconds, if you want to use an integer as seconds, it's easy to use it like: Ne3 being N = seconds.

1e3 = 1000 = 1 second

Edit:

Hex numbers are written with the prefix 0x.

like image 69
António Almeida Avatar answered Oct 01 '22 06:10

António Almeida