Node js execute function before complete multiple lines of code
问题 This function: function print(){ console.log('num 1') setTimeout(() => { global.name = 'max' console.log('num 2') },9000); console.log('num 3'); } print(); console.log(global.name) is priting this: num 1 num 3 undefined num 2 And I need to: print num 1 wait untill the 9 seconds set the global.name = max print num 2 print num 3 console.log(global.name) print max and not undefined I wrote this code in python and it executese line by line because there is nothing called sync and async. I need