Yes. You can define a constant (eg IS_SERVER) which your bundler (eg esbuild) replaces with a specific value depending on what environment you’re targeting. There are also ways to detect it using runtime globals that are only defined within the browser although that can be monkeypatched by your own code or 3p libraries you import (not common but could be a compat layer you add to make server side JS behave more like a browser).
Something like
if ('Bun' in globalThis) ...
if ('Deno' in globalThis) ...
if ('window' in globalThis) ...
could be used to determine the runtime.
That certainly works for Bun and Deno, not sure about what is effective in Node, though.
Checking for process.versions.{node,bun} works, not sure if Deno has an equivalent.