How to create your first Javascript program
Description
Save the following code into a text file and name it as test.htm. Drag and drop test.htm to a browser.
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
document.writeln("Hello");
</script>
</head><!-- w w w . j av a 2 s . c o m-->
<body>
</body>
</html>
The code above generates the following result.
The code above outputs string "Hello" to the web page.
Statements
Each statement represents a single command, and statements are usually terminated by a semicolon (;).
The following code has two statements and each outputs a string to the web page.
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
document.writeln("This is a statement");
document.writeln("This is also a statement");
</script>
</body><!-- w ww . j a v a2 s. c om-->
</html>
The code above generates the following result.