Environment is browser
Determines if the current runtime environment is a browser so that front-end modules can run on the server (Node) without throwing errors.
typeofvalues of both
Document(globals usually only available in a browser environment unless they were explicitly defined), which will return
trueif one of them is
typeofallows globals to be checked for existence without throwing a
- If both of them are not
undefined, then the current environment is assumed to be a browser.
const isBrowser = () => ![typeof window, typeof document].includes('undefined');
isBrowser(); // true (browser) isBrowser(); // false (Node)