JavaScript – Hello world! example

In this post we are going to see simple hello world example. Below example writes “Hello world” to html document.

<h1>Hello world example</h1>
<script type="text/javascript">
document.write("<p> hello world!</p>");

Output is:

Hello world example
hello world!

In above example JavaScript code is written in <script> tag. Use type=” text/javascript” attribute to declare JavaScript language.
Statements inside <script> tag are executed by browser.

What is document?

This is object of html document loaded into browser. We have used write method to write content into html page. We will see all methods and properties in next post. Note: Don’t use document.write(“’); method in real life.. It will overwrite entire page with  contents provided in the method. We have used for demo purpose. We will see other techniques to write content on html page.

Leave a Reply

Your email address will not be published. Required fields are marked *