Console.log chỉ hiển thị nội dung tại thời điểm vật thể được xem, chứ không phải vào lúc lệnh được thực thi

As you can see below, even though the array is logged before the mutating method is applied, the debugger still shows it as already being applied. However, its elements and properties when called specifically still return correctly:

If I add a breakpoint before the methods, then it is correct. If I continue then the result doesn’t change.

const array = ["cat","dog","mouse"]
console.log('array', array);
console.log('array[0] :>> ', array[0]);
console.log('array.length :>> ', array.length);

array.splice(0, 1)
// array.push('bat')
debugger

Nguồn:: Stack Overflow, console.log() async or sync?, console.log() shows the changed value of a variable before the value actually changes


Cập nhật lần cuối : 30 tháng 6, 2024
Tạo : 12 tháng 10, 2023