How do I include a custom JavaScript file in a module?
This is the right &amp; simple way to include any JS file in Drupal 7.


Create a folder named i.e. js, inside your module folder.
Inside that folder place (modulename).js file.

Note: Drupal JS code has a specific format as follows:

(function ($) {
  $(document).ready(function(){
    alert("Hello world!");  //here we can add our JS code
  });
})(jQuery);

Open (modulename).info file &amp; add:

scripts[] = js/(modulename).js
Clear Cache &amp; Run.