Skip to content

Instantly share code, notes, and snippets.

@akshaye
Created January 24, 2013 09:05
Show Gist options
  • Save akshaye/4618936 to your computer and use it in GitHub Desktop.
Save akshaye/4618936 to your computer and use it in GitHub Desktop.
Things i learned while reading Async Javascript

1 Async output

JavaScript output is almost always async. For instance, you can make multiple updates to DOM, but user won't see any changes until control returns to event queue. implicitly, any change you make queues a 'redraw' event.

2 Not all async behavior is obvious

For example, in webkit based browsers, console.log is async:

(function(){
    var obj = {};
    console.log(obj);
    obj.foo = "hello";
})();

Above code will log {foo: 'hello'} in chrome and safari, but {} in node.

(This seems to have been corrected in chrome now.)

3 setTimeout and setInterval are imprecise

Both setTimeout and setInterval have a minimum delay of 4ms, according to the HTML spec.

"If the currently running task is a task that was created by the setTimeout() method, and timeout is less than 4, then increase timeout to 4."

4 Each event at bottom of stack

Implication of JavaScript's event loop runtime is that each event that fires will be at the bottom of the stack. Hence, stack trace will not give much context about where the event was initiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment