The example demonstrates how to use JavaSript to write text on a web page.
<html>
<body>
<script type=”text/javascript”>
document.write(”<h1>Hello World!</h1>”);
</script>
</body>
</html>
Output:
Hello World!
Explanation:
document.write(”<h1>Hello World!</h1>”); is a JavaScript statement.It also shows how to use JavaScript to write HTML tags on a web page.
Note the following points:
- The JavaScript statement is enclosed in the <SCRIPT> and </SCRIPT> tags.
- The code informs the browser to write some text in the document. In this case, the text to be written is Hello World! The text is enclosed in quotes and placed inside parenthesis. The quotes are NOT written along with the text; they help to signify the beginning and the end of the text.
- The text in the <h1> </h1> tags demonstrate how to use JavaScript to write HTML tags on a web page.
- Though, it is not necessary to end JavaScript statements with a semi-colon, its always a good habit.
