Embedding and Including Javascript

by Haig. Average Reading Time: less than a minute.

Javascript is a programming language that is usually included or embedded into HTML files to add behaviours that HTML is not capable of.


Here’s a simple example of how javascript is embedded in an HTML page:

			<title>This is a JavaScript example</title>
			<script language="JavaScript">
				document.write("Hello World!");
			Hey there!

Usually, JavaScript code starts with the tag

<script language="JavaScript">

The javascript ends with the tag



The javascript code is commonly placed between Head tags but sometimes it’s embedded in the Body tags, like this:

			.....// The code embedded in the <body> tags.

Why do we place JavaScript code inside comment fields ? It’s for ensuring that the Script is not displayed by old browsers that do not support JavaScript. This is optional, but considered good practice. The LANGUAGE attribute also is optional, but recommended. You may specify a particular version of JavaScript:

	<script language="JavaScript1.2">


You can use another attribute SRC to include an external file containing JavaScript code:

	<script language="Javascript" src="hello.js"></script>

For example, shown below is the code of the external file hello.js:

	document.write("Hello World!")

The external file is simply a text file containing JavaScript code with the file name extension “.js”.

Next up: Write and Writeln

No comments on ‘Embedding and Including Javascript’

Leave a Reply