JavaScript is basically used for validating web pages at the client end. Its task is to validate the user input on the web pages, thus saving the server resources.

                The statements are placed within the <script>   </script> HTML tags. The <script> </script> tags alert the browser to interpret all the statement written between the script tags as a script. Script is a client side program; it is used to extend the functionality of html documents and to handle it in the most interactive way. The correct place to keep these script tags is in the <head> </head> section but we can place it anywhere on the web page.

There are two important attribute of a script tag:

1.       Language: It specifies which language version we are using, basically the language is Java Script.

2.       Type: This attribute is used to indicate the scripting language to use; its value will be text/javascript.

This is first part of the Java Script code:

<script type="text/javascript">

    //Java Script Code to be written here     



The above program would not print anything on the browser.

There is a function of a JavaScript known as document.write (), this function is used to print the string on the browsers screen.


<html xmlns="">

  <head runat="server">


  <script type="text/javascript">


      function displayMsg()


        document.write("Hello! Welcome to the world of JavaScript")





  <input id="btnSubmit" type="button" value="Display Message" onclick="displayMsg()"/>        



Output of the above code:


Hello! Welcome to the world of JavaScript


The above lines will be printed on the browsers screen.


There are places when some browsers do not support Java script code, there are compatibility issue so there we use comment <! — Comment /-->. This will prevent the browser in executing the lines of code that are placed in the comment section when there are compatibility issues as shown in the example.


<script type="text/javascript">


    function UsingComment() {

        alert("Showing the use of Comment")





Few Points to remember Java Script:


1.        JavaScript is a case-sensitive language. For eg. Document.write() function is different from the document.write() function, the first one will not print any output on the screen. So care must be taken in typing the variables, function names and any other identifiers otherwise program will not give the correct output.


2.        JavaScript ignores white spaces, tabs and new lines. We can use as much spaces we want to give a beautiful look to our program.


3.       Simple statements are usually followed by semicolons but it is not compulsory if to place semicolons if both the statements are on different lines.

For example:

var a = 40

var b = 25

The above code are allowed in JavaScript if they both are written on different lines.


But we have to give semicolons between them if we have both the statements on the same line as follows   var a= 40; var b=25;


4. As every language has comments same with the JavaScript, JavaScript supports both C / C++ styles of code. 


Single Line Comment:



// This is a single Line comment. 


Multiple Lines Comment :




    This is a multiline

    comment in





               This article gives you knowledge about Java Script and how to declare sections of Java Script in our html page. Which syntax to use while declaring Java Script sections of code in our html page. How to use comments in our Java Script programs and so on.

Leave Comment