0

Consider the following code

    let cat={name:'foo',color:'white'};
    Object.defineProperty(cat,'color',{enumerable:false})
    console.log(cat);
    Object.defineProperty(cat,'color',{enumerable:true})
    console.log(cat);

If I paste this code in chrome console, it still shows the color property in both log statements, but I run this in nodejs it show only in bottom log statement, what can possibly the cause of this behavior?

Here are the screenshots of NodeJS console output

NodeJS output

And here is the screenshot of chrome console

Chrome Output

Lint
  • 895
  • 3
  • 13
  • 32
  • 1
    This is console implementation specific. If you manually iterate enumarable properties to log them you'll get consistent output. see: [Console: Spot enumerable and non-enumerable properties](https://developer.chrome.com/docs/devtools/console/reference/#enumerable-properties), Chrome specifically logs all properties for debugging purposes, but highlights them differently. – pilchard Aug 13 '22 at 08:48
  • 1
    "*what can possibly the cause of this behavior?*" there is no specification for consoles. They show you what they show you. – VLAZ Aug 13 '22 at 08:48
  • 1
    That's a poor dupe target, this has nothing to do with lazy evaluation. – pilchard Aug 13 '22 at 08:53
  • 1
    The `enumerable` config parameter is just a flag for changing the behavior of an iterating context, not for hiding a object key. – n-- Aug 13 '22 at 09:00

0 Answers0