> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/scope/global/is-in-global-scope.md).

# isCurrentlyInGlobalScope()

[JS](/web/js.md) ⟩ [concepts](/web/browser/concepts.md) ⟩ [scope](/web/js/scope.md) ⟩ [global](/web/js/scope/global.md) ⟩ isCurrentlyInGlobalScope()

{% hint style="success" %}
check if the current context ([this](/web/js/concept/execution-context/this.md)) is in the [global scope](/web/js/scope/global.md).
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}

```javascript
// must use arrow function to get the enclosing context
const isCurrentlyInGlobalScope = () => this === globalThis;
```

* in browsers

```javascript
isCurrentlyInGlobalScope()    // ✅ true (top-level scope == global scope)
```

* in Node.js

```javascript
isCurrentlyInGlobalScope()    // ❌ false (top-level scope == module scope)❗️ 
```

{% endtab %}

{% tab title="👥 相關" %}

* must use [arrow function](/web/js/val/func/arrow.md) to get the enclosing context (current [this](/web/js/concept/execution-context/this.md)).
* [globalThis](/web/js/scope/global/object/this.md) - the global object.
  {% endtab %}
  {% endtabs %}
