console.log() shows the changed value of a variable before the value actually changes

后端 未结 7 2174
无人共我
无人共我 2020-11-22 02:09

This bit of code I understand. We make a copy of A and call it C. When A is changed C stays the same

var A = 1;
var C = A;
console.log(C); // 1
A++;
console.         


        
7条回答
  •  生来不讨喜
    2020-11-22 02:37

    The latest guidance from Mozilla as of 11/2020:

    Don't use console.log(obj), use console.log(JSON.parse(JSON.stringify(obj))).

    This way you are sure you are seeing the value of obj at the moment you log it. Otherwise, many browsers provide a live view that constantly updates as values change. This may not be what you want.

提交回复
热议问题