Computer >> Computer tutorials >  >> Programming >> Javascript

Should I write my script in the body or the head of the HTML?


It is suggested that you should place the script within the <head> tag or <body> tag. It is good for performance to add JavaScript in <body> element.

Example

Here is an example to add <script> under <body>…</body> −

<html>
   <body>
      <script>
         <!--
            document.write("Hello World!")
         //-->
      </script>
   </body>
</html>