What is the difference between synchronous and asynchronous programming (in node.js)

前端 未结 10 1693
情歌与酒
情歌与酒 2020-11-22 01:49

I\'ve been reading nodebeginner And I came across the following two pieces of code.

The first one:

    var result = database.query(\"SELECT * FROM hu         


        
10条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 02:25

    In the synchronous case, the console.log command is not executed until the SQL query has finished executing.

    In the asynchronous case, the console.log command will be directly executed. The result of the query will then be stored by the "callback" function sometime afterwards.

提交回复
热议问题