๐Ÿ’พisCurrentlyInGlobalScope()

JS โŸฉ concepts โŸฉ scope โŸฉ global โŸฉ isCurrentlyInGlobalScope()

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