Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Asynchronized programming seems to be natural in Javascript - it is the "first choice" to do many things.

But in most other programming languages, asynchronization is more like a second choice rather than first choice.

What makes asynchronizated programming so popular and natural to Javascript?

share|improve this question

closed as too broad by gnat, Jim G., MichaelT, Corbin March, BЈовић Aug 5 '13 at 6:58

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 9 down vote accepted

Especially when used in a browser environment, there are no threads (let's ignore the rather new WebWorkers for now) available - all JS runs in a single thread which is usually the same one that also handles e.g. rendering of the page.

So performing actions in a blocking manner is simply not an acceptable option - especially since most actions that involve IO in JavaScript usually cause network IO which, unlike disk IO, is usually rather slow and thus blocking everything until a request finished is not acceptable.

share|improve this answer
WebWorkers seem to be useless for the purpose they were created anyway, the serialization/deserialization overhead is insane – Esailija Aug 4 '13 at 23:31
@Esailija: I've found them useful occasionally within Firefox extensions. However, on a normal website I think they'd introduce more issues than they'd resolve. I think this might change over time. The overhead isn't a big deal if you're doing something non-trivial. And to be fair, threads are pretty expensive in most other languages, too. – Brian Aug 5 '13 at 1:02
@Esailija Note that WebWorkers transferable objects solve some of the serialization issues, by allowing a worker to relinquish its hold on some memory space and give it to the main thread (thereby avoiding the need to do a copy at all). I believe the usefulness of this technique is limited by the fact that only a few object types can be passed in this way. – apsillers Aug 5 '13 at 13:13
that makes perfect sense, thank you very much – Howard Aug 6 '13 at 4:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.