When is JavaScript synchronous?

前端 未结 7 2166
孤独总比滥情好
孤独总比滥情好 2020-11-22 03:48

I have been under the impression for that JavaScript was always asynchronous. However, I have learned that there are situations where it is not (ie DOM manipulations). Is

7条回答
  •  暖寄归人
    2020-11-22 04:36

    JavaScript is single-threaded, and all the time you work on a normal synchronous code-flow execution.

    Good examples of the asynchronous behavior that JavaScript can have are events (user interaction, Ajax request results, etc) and timers, basically actions that might happen at any time.

    I would recommend you to give a look to the following article:

    • How JavaScript Timers Work

    That article will help you to understand the single-threaded nature of JavaScript and how timers work internally and how asynchronous JavaScript execution works.

提交回复
热议问题