wiki/content/20201116170538-globalthis.md

25 lines
377 B
Markdown
Raw Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-29 18:27:12 +00:00
date: 2020-11-16
2024-05-06 20:40:05 +00:00
id: 828f0c1c-f17a-40fe-9926-50b87a2551a9
title: globalThis
---
# Description
This eases yet another JavaScript pita. Replaces the different global
object names:
- `window` (browser)
- `global` (node)
- `self` (web workers)
with `globalThis`.
# Syntax
``` javascript
if (typeof globalThis.alert === "function") {
globalThis.alert("hi");
}
```