
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Why doesn't JavaScript support multithreading?
JavaScript used to be single-threaded. It runs using what is called an event loop.
The Event Loop has one simple job — to monitor the Call Stack and the Callback Queue. If the Call Stack is empty, it will take the first event from the queue and will push it to the Call Stack, which effectively runs it.
JS in browsers doesn't support multithreading in the event loop as it is not needed for 99.999% of the websites. The event loop handles everything seamlessly.
For the remaining apps, devs can use web workers. Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface. In addition, they can perform I/O using XMLHttpRequest (although the responseXML and channel attributes are always null). Once created, a worker can send messages to the JavaScript code that created it by posting messages to an event handler specified by that code (and vice versa). This article provides a detailed introduction to using web workers.
- Related Articles
- Why doesn't MySQL support millisecond / microsecond precision?
- Why doesn't C++ support functions returning arrays
- Why doesn't JavaScript have a goto statement?
- Python3 - Why loop doesn't work?
- Why milk doesn't contain Vitamin C?
- Why Black hole doesn\'t emit the light?
- Why dispersion doesn't occur in glass slab?
- How to deal with Internet Explorer and addEventListener problem "Object doesn't support this property or method" in JavaScript?
- Why JavaScript 'var null' throw an error but 'var undefined' doesn't?
- Why does C++ require a cast for malloc() but C doesn't?
- Why final variable doesn't require initialization in main method in java?
- How a magnet attracts iron ? And it doesn't attract insulator. Why?
- Why subclass doesn't inherit the private instance variables of superclass in Java?
- Metal react with water but why non-metal doesn't react with water?
- If air pressure acting on chair then why it doesn't get crushed?
