๐พisCurrentlyInGlobalScope()
JS โฉ concepts โฉ scope โฉ global โฉ isCurrentlyInGlobalScope()
check if the current context (this) is in the global scope.
// must use arrow function to get the enclosing context
const isCurrentlyInGlobalScope = () => this === globalThis;
in browsers
isCurrentlyInGlobalScope() // โ
true (top-level scope == global scope)
in Node.js
isCurrentlyInGlobalScope() // โ false (top-level scope == module scope)โ๏ธ
Last updated
Was this helpful?