Is javascript single-threaded?

前端 未结 2 805
时光说笑
时光说笑 2020-12-19 15:17

Is javascript running on single thread? If I declare a global array, and start changing it (eg removing elements) on AJAX callback and at the same time start changing the ve

相关标签:
2条回答
  • 2020-12-19 15:30

    JavaScript is single threaded.

    The referenced post discusses differences of setTimeout on different machines...


    HTML5 introduces the concept of WebWorkers which executes JavaScript on multiple background threads. Though it is not supported on all browsers...

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

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

    0 讨论(0)
  • 2020-12-19 15:44

    is it guaranteed to be always single-threaded on all browsers?

    Yes.

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

    0 讨论(0)
提交回复
热议问题