We can we use global.console.log('A')
should mean that console is a property of the global object. But using console.log(global)
, I don't see any property named 'console' ?
Asked
Active
Viewed 179 times
1

CertainPerformance
- 356,069
- 52
- 309
- 320

user123456789
- 424
- 4
- 15
1 Answers
4
It's not enumerable, so it doesn't show up when just logging the plain global
object. But it's still directly on global
:
>global.hasOwnProperty('console')
true
> Object.getOwnPropertyDescriptor(global, 'console')
{
value: {
...
},
writable: true,
enumerable: false,
configurable: true
}
If you want to examine all properties on an object, use Object.getOwnPropertyNames
:
Object.getOwnPropertyNames(global)
(There are lots of non-enumerable properties on global
, and only a few enumerable ones)

CertainPerformance
- 356,069
- 52
- 309
- 320
-
What about the second question ? – user123456789 Nov 11 '19 at 09:56
-
1Different questions should be separated into different posts, but the answer to your second question is https://stackoverflow.com/questions/19850234/node-js-variable-declaration-and-scope - the top level of a module is *not* the global scope – CertainPerformance Nov 11 '19 at 10:10