Check if the code is running in the browser

We can detect if the current code is running in the browser by checking the existence of window and document objects:

const isBrowser = typeof window === 'object' && typeof document === 'object';

More

Previous
Check if an element is visible in a scrollable container
Next
Check if the native date input is supported