Why is JavaScript single-threaded?

I just read through this piece about callback-less JavaScript coding, and it raises a question I've never seen answered, that I've been puzzled about ever since I learned that there are just a couple of threads in a JavaScript app running in the browser.

The question is this -- why?

It's been a long time since I worked in an environment that had such a constraint.

I kept looking for the JavaScript verb that forks off another thread. Until I realized there was no such verb. Why not just relax the rule and let a JavaScript app spawn a certain number of threads. And if it needs more, ask the user if that's okay. Like getting more memory in an iPad app.

It crossed my mind that this might be a way for a web page to crash your browser. But I'm pretty sure I can already do that with a simple loop that does nothing and never terminates.

while (true) {}

Anyway -- if you have any idea please post a comment.


Posted: Thu, 15 Aug 2013 21:20:57 GMT