With JavaScript, you can put JavaScript anywhere on the page, whether inside <head> or <body> tag. But, it is a good practice to add JavaScript in the footer i.e. just before closing the <body> tag. This is because −
- It loads script faster.
- It will not block any DOM content to load.
- It loads the web page before loading JavaScript
- Improves display speed
- Page loads faster