💾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?