Don't show file contents on server

If a user goes to my site and types mysite.com/myjs.js how do I prevent them from seeing the contents of myjs.js?

If you want to expose only some subset of files, you need to configure your server to do that. For instance only allow to fetch index.html. How to do it, depends on what server you use.
Note that if your index.html file references myjs.js, it is still downloaded and available for user.

So, everything that runs in browser is and should be available for inspection.
If you want to hide the details, do the processing on the back-end.