JavaScript – Put JavaScript inside Body Tag

JavaScript inside Body Tag

JavaScript code can be placed inside the <body> and </body> tag of the HTML document.

Using JavaScript code in the body section will be better for the loading of the web page or HTML document.

We can put JavaScript code in the <head> section also but that will take more time to load the webpage.

Most of the time JavaScript code can be placed before the closing of the </body> section.

HTML / JS Code

<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
document.write("Hello World!!");
</script>
<p> This is saying hello world. So I say hello to the world. Please accept my hello.</p>
</body>
</html>

Output

This is saying hello world. So I say hello to the world. Please accept my hello.