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.

Introduction to JavaScript

JavaScript developed by Netscape in 1995. JavaScript is structured language much similar to ‘C’ language. Today JavaScript is
essential and popular language.

What is JavaScript?

JavaScript language is scripting language and known to all major browsers like IE, Mozilla, Chrome, Safari, and Opera. This language used
for client side scripting. It executes at client side i.e. into browser.

What JavaScript provides?

Client side events:

JavaScript supports client side events of an HTML element. For example, button is clicked, page finished loading.

JavaScript can interact with elements:

JavaScript can access, change content of element.

Validate user input:

JavaScript makes easy to validate the user input at client side. We can save call to server. We can make page more interactive using

To run JavaScript code, you need browser which supports JavaScript.