Whats the use of adding javascript to HTML?

You can make the website more interactive when you use javascript.

Javascript can improve your website and increase the amount of time people spend on your webpage.

Validating the fields of a Form

Javascript is great to ensure the user has filled in all the necessary fields for a form after hitting the submit button. Sometimes users might miss out a field when they fill in a contact us form and javascript code can help highlight the missing entries and let the user know which fields need to be filled in.

By using javascript, you can also make the webpage less cluttered as you can put the javascript code into an external file and just call this javascript function.

This would help to reduce the loading time for users and it also makes your code easier to maintain.

An example of how to call the javascript from an external source is

<script src="sample-javascript.js"></script>