I want to use JavaScript for module custom HTML in Joomla! How to do this?

You can insert JavaScript any where in Custom module. But you should note the following 2 things: 

  1. You need to change the Default Editor to Editor - None in Global Configuration before using custom code in Custom HTML Module or an Article.
  2. If your code is cleaned by the editor after saved, you need to change the settings of your editor to allow code, script,.. in your contents.

Read more about: TinyMCE editor cleans up my code