Most of the websites I work on have at least two environments: staging (for testing) and production (the live site). Each environment has a different configuration, e.g. staging will typically have some form of debugging mode. In PHP I can usually work out which environment to use by examining the current file path, but I also need to do something similar for JavaScript.
Fortunately it is easy to set variables based on the hostname in JavaScript:
var debug_mode = (window.location.host === 'staging.example.org') if (debug_mode) { console.log('debug mode is on'); }
The above code will enter a log message in the JavaScript console, but only if the code is executed on the staging site.