Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!


JavaScript – JavaScript in Head and Body Tag

JavaScript in Head and Body

JavaScript can be written inside both the <head> section and <body> section. Sometimes we need to write the JavaScript code in both sections to better understand or calling the different functions.

While writing JavaScript code <head> and <body> sections we have to use <script> tag for both.

Here you can see an example where I have written JavaScript code in two ways by putting it inside the <head> section and by putting inside the <body> section. These two are the formal ways to write scripting code.

I always put it in the body section of the HTML document because It will help to load the page faster.

HTML / JS Code

        <script type="text/javascript">
   function book(){
    alert ("JavaScript is Awesome");
     <script type="text/javascript">
    document.write("Leave it!! No need to develop.");
        <input type="button" onClick="book()" value="DEVELOP">




About Author provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like


JavaScript – Introduction, History, and Syntax

  • September 17, 2020
What is “JavaScript”? The first appearance of JavaScript was made in Netscape 2.0 in 1995 with a name Live Script.

JavaScript – Write Program to Print Hello World!!!

  • September 17, 2020
JavaScript is scripting language which is similar to C. It is syntax and logic are similar to C, C++ and