0

I have a console.log on an object, then I delete a key, then console.log again. The code below behaves as expected, the first console log has one and two and the second console log only has two

const a = {
  one: '1',
  two: '2'
}

console.log(a);
// Will print { one: "1", two: "2" }

delete a.one;

console.log(a);
// Will print { two: "2" }

However my actual code behaves strangely. If I just log the object I see the value I expect:

console.log(a);
// Will print { one: "1", two: "2" }

If I delete then the key is deleted for both console logs, even though one appears first in the code:

console.log(a);
// Will print { two: "2" }

delete a.one;

console.log(a);
// Will print { two: "2" }

I cant share my full project and I havent been able to recreate this behaviour. I know this is an open question but what are the potential causes of this behaviour?

Evanss
  • 23,390
  • 94
  • 282
  • 505
  • What code is running before the unexpected `console.log(a); // Will print { two: "2" }`? It seems strange that the property would be missing if you defined `a` as it's written at the top – byxor Nov 11 '20 at 11:14
  • 2
    [Is Chrome's JavaScript console lazy about evaluating arrays?](https://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays) – Andreas Nov 11 '20 at 11:15

0 Answers0