JS to determine test/beta/prod environment
Would you specify your question further? Meanwhile, the access tokens to the production environment API and to the test/beta are different, which prevents one from accidentally running the unwanted environment.
For Instructure cloud hosted Canvas instances, I think you can check the "ENV.RAILS_ENVIRONMENT" variable as a more universal way of determining the environment than just looking at the URL. Looking at the URL would be find if you're developing for a single canvas instance where you know for sure what the URL for each environment is, but if this is for wider audience, the URLS could vary and there could even be more than one URL for each environment.