Files
reference/source/_posts/note/javascript/misc/check-if-the-code-is-running-in-the-browser.md
T
2022-11-16 14:10:09 +08:00

417 B

title, tags, layout
title tags layout
How to check if the code is running in the browser in JavaScript
JavaScript
one-line
js
note

In this Article we will go through how to check if the code is running in the browser only using single line of code in JavaScript.

Let's define this short function:

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