First JavaScript

We have already learned the JavaScript syntax, the tools to create scripts and how to enable JavaScript in the browser. Lets create the first JavaScript. Here is an example and explanation.

w3r video tutorialsWatch write your first JavaScript video tutorial.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>JavaScript First Example</title>
</head>
<body>
<script type="text/javascript">
document.write("First JavaScript");
</script>
</body>
</head>

Explanation

The first nine and last three lines are HTML codes.

Everything except the code written <script type="text/javascript"> and <script> tags is html.

<script type="text/javascript">

The above statement is the opening script tag tells the browser to expect a script (here it is JavaScript) instead of html.

document.write("Hello World");

The above part is a JavaScript command ( document.write() ) which writes text ( here it is "First JavaScript") to a web page.

</script>

This is the last statement tells the browser the end of the script ( here it is JavaScript).