Javascript banner image.

Here is a basic “Hello World!” exercise in Javascript. Online code editors like JSFiddle and Codepen truly come into their own when learning Javascript.

This simple example uses Javascript’s alert method to display a “pop-up” type message when the page loads (this is not a good thing to do on your website, by the way). Check it out in this Fiddle (click on the Result tab to load the page and run the script):

Or copy-paste the below code into an HTML file and fire up your browser!

<html>
    <head>
	<title>Hello World! Javascript</title>
    </head>
    <body>

        <h1>Hello World! Javascript</h1>

        <script>
	    alert("Hello World!");
        </script>

    </body>
</html>

Javascript code can be written in your HTML files between the <script> tags. The <script> tags are in turn nested in the <head> or <body> tags.

Your next step is to use an event to fire your Javascript code. Head on over to the post Javascipt’s onclick() event.

By MisterFoxOnline

CAT Educator

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.