Home > Article > Web Front-end > Why Does Console.log() Display Modified Values Instead of Original Values in Chrome?
Console.log() Inconsistencies in Chrome when Logging Objects and Arrays
In Google Chrome, unexpected behavior occurs when using console.log() to log nested arrays or objects. If you modify the innermost value of an array or object after logging it, console.log() will display the modified value, not the original values at the time of logging.
Steps to Reproduce
To recreate the issue:
This inconsistency also affects objects and arrays stored in variables (testb, testc).
Underlying Issue
After extensive research, it was discovered that this issue was previously reported as a bug in WebKit (https://bugs.webkit.org/show_bug.cgi?id=35801). Chromium developers acknowledged the issue, but stated that a fix was unlikely due to technical limitations.
Fix and Inconsistencies
However, a fix was implemented in WebKit in 2012. Despite this, Google Chrome has yet to adopt the fix. As a result, console.log() behavior differs depending on whether the console window is open at the time of logging.
Conclusion
This bug in Google Chrome's console.log() functionality persists and affects debugging efforts. It is recommended to be aware of this inconsistency and consider alternative debugging methods until the issue is resolved in Chrome.
The above is the detailed content of Why Does Console.log() Display Modified Values Instead of Original Values in Chrome?. For more information, please follow other related articles on the PHP Chinese website!