Here are five lines of JavaScript:
" document " in globalThis ; " Bun " in globalThis ; globalThis . process ?. versions ?. bun ?? " not Bun " ;
import { readdir } from " node:fs/promises " ; ( await readdir ( " . " )). length ;
Enter fullscreen mode
Exit fullscreen mode
What do they print?
It depends on where they run. Run them in Bun and there's no document , there is a Bun , and readdir counts your files. Run them in a browser and document is there, Bun isn't, and that node:fs import doesn't make it past the build.
Most of us switch between those worlds all day. This post is about turning that into one switch per tab, in JSLab . It's our own tool, so discount the praise accordingly. The snippet above comes straight from the runtime docs .
Three runtimes, one menu
Each JSLab tab runs its code in one of three runtimes.…