Question: Can we use any type of javascript code as a external .js file or sometime it's necessary to place in `<head>`?

Answer: 
Unless it is a Dynamic content which is placed by the server side scripts (very rarely used as there are many more better alternative methods) .. You can use JS in an external file .. 

External js is re-usable .. I mean can be used by more than one HTML page .. So obviously it brings down the burden on browser ..

The site providing the live telecast or the NEWS/information (example:cricket scores etc) real-time examples for Dynamic content ..
You can place it all in an external file. It's much cleaner, and easier to maintain. It's a good practice to keep Javascript and CSS in their own external files. Do away with inline switching between CSS, HTML and Javascript for a much better organized project and less frustration down the road.