A Fun Fact About the Chrome DevTools JS Console

Let me start by saying that Google's Chrome DevTools are amazing and if you're not using them, you definitely should. Chrome gives you several methods you can use to debug your code, one of the easiest being a JavaScript console. You have probably noticed that when you use this console to print out a nested object (such as an array of objects, for example), Chrome give you a collapsed object that you can click to see the nested objects and properties:
What you might not realize, however, is that these logs of collapsed objects point to a variable stored in memory. Because objects are mutable in Javascript, this means that what you're seeing in the console is not necessarily an accurate representation of what that object looked like at the moment console.log was called.
If you're like me and have always assumed that the Chrome console shows you exactly what a variable looks like at a given place in your code, this idiosyncrasy can make debugging extremely difficult. While I was figuring this out, I had to remind myself several times that my computer is not actually a magical entity that can predict and print the future. I restructured the entire program I was working on before I realized what was going on, at which point I considered just throwing myself and my laptop into the sea.
Let's say we want to run this code:

var nestedObj = [{  
  cat: 'meow'
}, {
  dog: 'woof'
}, {
  pig: 'oink'
}];

console.log(nestedObj); // ?

nestedObj.push({  
  cow: 'moo'
});

I expect the nestedObj to be printed without the {cow:'moo'} entry. If I run this file using node, that is exactly what happens:
However, when I run the exact same code in Chrome, I get this:
The {cow: 'moo'} entry has already appeared! This is because the console is showing nestedObj as an object in memory at the present moment, not at the time it was printed.
Chrome DevTools can be your best friends, but you have to make sure you're using them correctly. If you're trying to see what a nested object looks like at a given point, you can use breakpoints to pause the program and see what variables look like at that exact moment. If you still want to use the console, log a JSON.stringify-ed version to ensure that the log won't reflect future changes.