Previous
HTML and JavaScript 
Next
Dialogs 
ABC of JavaScript : An Interactive JavaScript Tutorial
The Basics

The Basics

You have already seen the mandatory Hello World program - so no need to repeat that here. From now one we will be concentrating one stuff inside the script tag. So when I say
alert("Hello World")
I mean the full HTML file with the 'alert("Hello World")' text inside the script tag. But if you want to try the code in the T-Box, you just have to type alert("Hello World") and not the full HTML content.

Writing Text

Wondering how to write a the string to the HTML area in the window rather than pop up a message box? This code will do the trick.

document.write("Hello World")

Be careful with this. Put it after the the <body> tag like this...

...
</head>
<body>
<script language="javascript">
document.write("Hello World")
</script>
...

If it is given before the body tag, a new page will be created with the 'Hello World' text. This will not work with the T-Box. T-Box will make a new page with the given text. Try it out if you must. Just click the 'Back' button to come back.

Before doing anything with this, I have to warn you that this is an old method - I will NOT recommended its use. If you have to write text into a page use innerHTML or other DOM functions.

Comments

Comment is what a programmer will enter into the source code to make the source more understandable. They are ignored by the interpreter. It is a good idea to explain what you are doing using comments - this makes the code more readable.

There is two types of comments in JavaScript...
// - The Line Comment
/* */ - Block Comment

Example
//This is a single line comment
/* This is a block comment. 
This will comment out every 
thing from the beginning
to the end */

Semi-colon

Semi-colons are not a must but it can be used to separate multiple statements on the same line. It is recommended that you use ';' at the end of all lines.

Example
i=0;i++;
Previous
HTML and JavaScript 
Next
Dialogs 
blog comments powered by Disqus