In this tutorial we will see how to make our first Javascript program using the Notepad ++ IDE. This program will display the famous "Hello World!" Message.

1 - Structure of a Javascript code

The syntax of a JavaScript code is of the form:

<script language="javascript">

Your code Javascript here !


or :

<script type="text/javascript">

Your code Javascript here !


Example (displaying a message on the screen)

You can display a message on the screen using the alert () function; )

<script type="text/javascript">

alert ('Hello World!');


 We can now wonder where are we going to insert this code?

There are two methods available to you:

  1. 1st method (directly between the body and / body tags)
  2. 2nd method (Javascript code between Head and Head tags)

In this tutorial we will see the first only, the 2nd will be treated in the next chapter
Example (Javascript code between Body and / Body:

<! DOCTYPE html>
<title> Hello World! </ title>
</ Head>
<script language = "javascript">

alert ('Hello world!');

</ Script>
</ Body>
</ Html>

This Javascript code is inserted directly between the body and / body tags, which means that it will be

executed directly when the page is loaded. To test this example :

  1. Launch your notepad ++ editor
  2. Copy the code above and paste it on Notepad ++
  3. From the Language menu choose HTML
  4. Save the file by choosing a name of your choice, for example myFirstProgram

To run the code now, click on the Run menu and choose Launch in (your Browser), for example Launch in firefox

At this moment a small window displaying the message Hello World! appears on the screen.

Younes Derfoufi

Leave a Reply