isBrowser
isBrowser
is a function that determines whether the currently executing JavaScript runtime is a browser environment.
Import
import { isBrowser } from "@tai-kun/surrealdb/utils";
Usage
function isBrowser(): boolean;
Arguments
None.
Return Value
Returns true
if the environment is a browser, otherwise false
.
Example
The following example determines whether the environment is a browser:
import { isBrowser } from "@tai-kun/surrealdb/utils";
if (isBrowser()) { document;}
Explanation
The function determines if it’s running in a browser environment by checking if the global variable document
is defined. Using the existence of the window
object would result in a false positive in server-side runtimes because frameworks like Deno add the window
object globally. The Remix web framework refers to this as a Document Guard.