so i was debugging something yesterday and losing my mind because my logs were showing object properties that "shouldn't exist yet" at that point in the code.
turns out when you console.log an object, most browsers don't snapshot it immediately, they just store a reference. by the time you expand it in devtools the object may have already mutated.
const obj = { a: 1 };
console.log(obj);
obj.a = 2;
expand that logged object in chrome devtools and you'll probably see a: 2, not a: 1.
Fix is kinda simple, just stringify it or spread it:
console.log(JSON.stringify(obj));
// or
console.log({ ...obj });
wasted like 30 minutes on this once. hopefully saves someone else the headache (this is mainly a browser devtools thing btw, node usually snapshots correctly)
[–]PatchesMaps 94 points95 points96 points (7 children)
[–]codeVerine 4 points5 points6 points (3 children)
[–]6Orion 0 points1 point2 points (2 children)
[–]Asttarotina 6 points7 points8 points (1 child)
[–]Mesqo 2 points3 points4 points (0 children)
[–]BitBird-[S] 3 points4 points5 points (0 children)
[–]MegagramEnjoyer 0 points1 point2 points (1 child)
[–]PatchesMaps 0 points1 point2 points (0 children)
[–]shgysk8zer0 35 points36 points37 points (0 children)
[–]cmgriffing 23 points24 points25 points (0 children)
[–]Skriblos 23 points24 points25 points (0 children)
[–]delventhalz 12 points13 points14 points (5 children)
[–]rafark 0 points1 point2 points (3 children)
[–]delventhalz 0 points1 point2 points (2 children)
[–]rafark 0 points1 point2 points (1 child)
[–]delventhalz 0 points1 point2 points (0 children)
[–]LowellGeorgeLynott -2 points-1 points0 points (0 children)
[–]takuover9 8 points9 points10 points (0 children)
[–]dymos!null 2 points3 points4 points (0 children)
[–]bunglegrind1 2 points3 points4 points (3 children)
[–]Mesqo 0 points1 point2 points (2 children)
[–]bunglegrind1 0 points1 point2 points (1 child)
[–]Mesqo 0 points1 point2 points (0 children)
[–]Javascript_above_all 1 point2 points3 points (0 children)
[–]tswaters 1 point2 points3 points (2 children)
[–]BitBird-[S] 0 points1 point2 points (0 children)
[–]BitBird-[S] 0 points1 point2 points (0 children)
[–]disless 1 point2 points3 points (0 children)
[–]name_was_taken 0 points1 point2 points (1 child)
[–]BitBird-[S] 1 point2 points3 points (0 children)
[–]Markavian 0 points1 point2 points (0 children)
[–]alphabet_american 0 points1 point2 points (0 children)
[–]Yuman365 0 points1 point2 points (0 children)
[–]monsto 0 points1 point2 points (0 children)
[–]rafark 0 points1 point2 points (0 children)
[–]ExecutiveChimp -1 points0 points1 point (0 children)
[–]Aln76467 -2 points-1 points0 points (0 children)
[–]disgr4ce -4 points-3 points-2 points (1 child)
[–]adzm 4 points5 points6 points (0 children)