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 62 times
1
![](../../users/profiles/9515207.webp)
CertainPerformance
- 260,466
- 31
- 181
- 209
![](../../users/profiles/8671940.webp)
user123456789
- 323
- 2
- 12
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)
![](../../users/profiles/9515207.webp)
CertainPerformance
- 260,466
- 31
- 181
- 209
-
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