In general, JavaScript execution in browser is considered as single-threaded. Does this single thread apply to all tabs open in a browser window?
In other words, if (different) JavaScript code are running in different tabs, they are all being executed using a single thread?
In addition, what happens when you have multiple windows of the same browser open and each window contains multiple tabs?
Finally, does the answers to the above depend on browser vendor/version etc?
Browsers aren't single threaded, but your script runs in a single runloop.
Chrome has a multi-process architecture and each process is heavily multi-threaded. The main goal is to keep the main thread (“UI” thread in the browser process) and IO thread (each process' thread for handling IPC) responsive.
Well, Chrome is multiprocess, and I think every process deals with its own Javascript code, but as far as the code knows, it is "single-threaded". There is no support whatsoever in Javascript for multi-threading, at least not explicitly, so it does not make a difference.
Chrome has a multi-process architecture and each process is heavily multi-threaded. In this document we will go over the basic threading system shared by each process. The main goal is to keep the main thread (a.k.a. “UI” thread in the browser process) and IO thread (each process's thread for receiving IPC) responsive.
There is no way to answer that in a generic way because this is browser implementation specific.
Pretty much every older browser always used a single thread for every tabs, but more modern browsers / versions might have changed that (for example, chrome has a thread per tab - actually, it even has a whole process per tab). EDIT: correction from the comment
Actually chrome uses Process-per-site-instance. That means a single site opened in multiple tabs will still get rendered by the same process
If you are asking it for performance reasons (kind of like asking "it is ok to block everything in my website using an eternal infinite loop, or will that spread to other tabs"), it is safer to assume that the thread is shared by everyone. If it is in the current browser then you planned for it, and if it isn't then you get better performance than planned for, hardly a problem.
In order to get some code running in its own thread, have a loop at Web Workers, but they are still far from being fully implemented in every "modern" browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With