Is Javascript synchronous(blocking) or Asynchronous(nonblocking) by default

后端 未结 3 1874
既然无缘
既然无缘 2020-12-02 17:29

I am trying to grasp on Javascript Asynchronous functions and callbacks.

I got stuck on the concept of callback functions, where I am reading on some places: they ar

3条回答
  •  Happy的楠姐
    2020-12-02 18:10

    Javascript is always a synchronous(blocking) single thread language but we can make Javascript act Asynchronous through programming.

    Synchronous code:

    console.log('a');
    console.log('b');
    

    Asynchronous code:

    console.log('a');
    setTimeout(function() {
        console.log('b');
    }, 1000);
    setTimeout(function() {
        console.log('c');
    }, 1000);
    setTimeout(function() {
        console.log('d');
    }, 1000);
    console.log('e');
    

    This outputs: a e b c d

提交回复
热议问题