1. 程式人生 > >node 命令中 & 和 && 的區別

node 命令中 & 和 && 的區別

package tex 三次 ont str 總結 lin cal amp

node first.js & node second.js

執行結果:
第一次:

  first.js
  second.js

第二次:

  second.js
  first.js

第三次:

  first.js
  second.js

第N次:

  ……

總結: 使用 & 連接符, first.js 和 second.js 的執行順序不確定

node first.js && node second.js

執行結果:
第一次:

  first.js
  second.js

第二次:

  first.js


  second.js

第三次:

  first.js
  second.js

第N次:

  ……

總結: 使用 & 連接符, first.js 和 second.js 的執行順序與命令中指定的先後順序相同

first.js

1 function first(){
2     console.log(‘first.js‘);
3 }
4 
5 module.exports = first();

second.js

1 function second(){
2     console.log(‘second.js‘);
3 } 4 5 module.exports = second();

package.json

 1 {
 2     "name": "logicaloperators",
 3     "version": "1.0.0",
 4     "description": "",
 5     "main": "index.js",
 6     "scripts": {
 7         "and": "node first.js & node second.js",
 8         "andand": "node first.js && node second.js"
 9
}, 10 "author": "", 11 "license": "ISC" 12 }

node 命令中 & 和 && 的區別