You can place the <script> tags, containing your JavaScript, anywhere within your web page, but it is normally recommended that you should keep it within the <head> tag or <body> tag.
It’s good for performance to add JavaScript in <body> element. Here’s an example to add <script> under <body>…</body> −
<html>
<body>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</body>
</html>
Here’s an example to add <script> under <head>…</head> −
<html>
<head>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</head>
<body>
</body>
</html>