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.
Watch write your first JavaScript video tutorial.
"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).