The “script” tag

JavaScript programs can be inserted into any part of an HTML document with the help of the <script> tag.

For instance:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Javascript Tutorial</title>
    <script type="text/javascript">
      alert("Hello World!");
    </script>
  </head>
  <body>

    <script type="text/javascript">
      document.write("Hello World Twice");
    </script>

  </body>
</html>

The <script> tag contains JavaScript code which is automatically executed when the browser processes the tag.


The <script> tag has a few attributes that are rarely used nowadays but can still be found in old code:

The type attribute: <script type=…>

The old HTML standard, HTML4, required a script to have a type. Usually it was type="text/javascript". It’s not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that’s an advanced topic; we’ll talk about modules in another part of the tutorial.

The language attribute: <script language=…>

This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.

1. Create New File in Atom / Notepad++
2. Save File as (Index.html)
3. Write Code for JavaScript (Using alert() and document.write() )
4. Open Index.html File with Firefox or Chrome Browser
5. First Output result will be in Alert() Box function
6. Last Step is Showing the Document.write() Display results in Text form.

Hence, This is the Very basic programming results to show and perform how JavaScript works in Browser.

Leave a Reply

Your email address will not be published. Required fields are marked *