当前位置:网站首页>console. Log() is an asynchronous operation???

console. Log() is an asynchronous operation???

2022-06-23 17:48:48Little fan

The above code , look consol.log() It's like executing asynchronously , But it's not . It's because when you click the expand button on the console , The browser will go to get the latest result Value . therefore result[0].a === 2

Just change it to the following , You can prove it !

var obj = { a: 1 };
var oldArray = [obj];
var result = oldArray.concat([1,2]);
// debugger
console.log(result[0].a);
obj.a = 2;
console.log(result[0].a);

Reference material :console.log Is an asynchronous flow ? I feel like I stepped on a pit - SegmentFault Think no

原网站

版权声明
本文为[Little fan]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/01/202201051804123243.html

随机推荐