如下代码,请给出输出结果,并解释原理。、
setTimeout(function () { console.log('start') new Promise(function (resolve, reject) { resolve(true) reject(false) console.log(1) }).then(function () { setTimeout('var x=2;console.log(2)') console.log(a) }, function () { setTimeout('var x=3;console.log(3)') console.log(b) }).then(function () { console.log(4) }, function () { console.log(5) }).catch(function () { console.log(6) }) }, 0) setTimeout(function () { const timer = setInterval(function () { console.log(7) }, 10) const start = Date.now() setTimeout(function () { while(Date.now() - start <= 30) {} clearTimeout(timer) try { console.log(x) } catch (e) { console.log(8) } }, 13) }, 0) console.log('end')