Skip to content

Instantly share code, notes, and snippets.

@cazala
Last active October 16, 2016 02:14
Show Gist options
  • Select an option

  • Save cazala/44fab99936251cdf7a582163915a5fe7 to your computer and use it in GitHub Desktop.

Select an option

Save cazala/44fab99936251cdf7a582163915a5fe7 to your computer and use it in GitHub Desktop.
How to tell if inside a Browser, WebWorker or NodeJS from Javascript
if (typeof window === 'object') {
// Browser
} else if (typeof importScripts === 'function') {
// WebWorker
} else if (typeof process === 'object' && typeof require === 'function') {
// NodeJS
} else {
// shell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment