Is javascript single threaded?

Does javascript work on a single thread? If I declare a global array and start changing it (for example, deleting elements) in an AJAX callback and at the same time start changing the same array in another function (called with SetTimeOut) - is there a risk of the race condition?

I found this topic: the state of the javascript race , someone said that race conditions are never in javascript because they always work in the same thread and in a single freeze frame. Does it depend on how the browser implements it or is it guaranteed that it is always single-threaded in all browsers?

+4
source share
2 answers

Is it guaranteed to always be single-threaded in all browsers?

Yes.

Of course, things like HTTP requests can work in different threads backstage, but when your Javascript code is executed, it can only happen from one thread at a time.

+4
source

JavaScript is single threaded.

This article discusses the differences of setTimeout on different machines ...


HTML5 introduces the WebWorkers concept, which runs JavaScript on multiple background threads. Although it is not supported in all browsers ...

https://developer.mozilla.org/En/Using_web_workers

http://dev.w3.org/html5/workers/

+2
source

Source: https://habr.com/ru/post/1401675/


All Articles