This is a quick snippet showing a basic wrapper for your JS code in Drupal. To understand it, I recommend reading the breakdown of Drupal's JS on drupal.org, which was written for Drupal 6 but mostly applies to Drupal 7, Drupal 8, and Drupal 9 too: https://drupal.org/node/304258