Basic Things of Implementing JavaScript to Web Pages

JavaScript can be typed in any text editor like notepad and can be stored separately with file extension.js. Usually, it is stored as a part of the HTML document. JavaScript codes are included in HTML documents by using the <script> tag.

The script tag is a non-empty tag and should be closed using the </script> tag. The script tag takes in two attributes namely language and src. The language attribute specifies the name of the scripting language used like JavaScript and VBScript. The src attribute specifies the name of the source file where the script is stored. The src is used only when the scripts are stored in a separate file. <script language = “ “ src = “ “ >

JavaScript codes goes here </script>

The document.write () method is used write output to the present document which would be explained when dealing with the document object. The following example illustrates the use of a script tag to embed JavaScript.


The script tag can be placed in between the <head> tag or the body tag. Normally the script tag is placed in between the head tag. To import scripting codes into your HTML document use the src tag. The following example illustrates the use of the src tag :

Document. write(“Welcome to JavaScript Style”)

 Save this code in a source file called script .js. This file is imported into an HTML document in the following manner. The SRC attribute can take an URL as its attribute value. The web server that provides the source file, should report the file’s MIME type as application / x-javascript.


Some browsers do not support JavaScript. To avoid errors when executing web pages that do not support JavaScript, the script is written within the HTML comment tags.

The JavaScript coding can be tested by loading the HTML document in the browser. Type the entire file path in the location of the browser or choose from the File menu.

JavaScript has the provision to give comment statements. To include a comment line just adds two forward slashes before the line:

// This is a comment line.

To add multi-line comment include the lines in between /* and */.