๐พ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)โ๏ธ must use arrow function to get the enclosing context (current this).
globalThis - the global object.
Last updated
Was this helpful?