It is a very common question where you should place your script tag. Few people prefer placing it after head tag and few prefer placing it somewhere in the body tag. If there is no manipulation of HTML elements on page load, then it is okay to place it in the head tag. But if
Reusability: You can reuse an external JavaScript file in multiple HTML files by simply adding reference to it. Any changes made to that external JavaScript file will affect all HTML files which are having reference of it. In case of inline JavaScript code, you have to write same code in multiple HTML files again and
External JavaScript code is placed inside an external JavaScript file. This external JavaScript file contains a lengthy JavaScript code. If you place same lengthy code inside a HTML file, it will make your whole code file look ugly. It’s a good habit to place all lengthy code inside an external JavaScript file and add path
Any JavaScript code, which is placed directly within a HTML file, is called Inline JavaScript code. Inline JavaScript code should not be lengthy. It should be a little piece of JavaScript code. Example of Inline JavaScript code is given below. <html> <head> <title>JavaScript Tutorial </title> </head> <body> <script type="text/javascript"> alert("Hello World"); </script> </body> </html>
As we know, JavaScript is extremely helpful in case of manipulating DOM of a web page. JavaScript can be used in a good way or bad way. There are 3 main disadvantages of using JavaScript. Disabling Option: Almost all the browsers have an option in settings to disable JavaScript. This means if someone has disabled