[Home] > Snippets  > Languages  > JavaScript  > Misc  >  Check if the code is running in the browser

Check if the code is running in the browser

JavaScript

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

TypeScript

const isBrowser: boolean = typeof window === 'object' && typeof document === 'object'