Previous HTML and JavaScript |
ABC of JavaScript : A JavaScript Tutorial The Basics |
Next Dialogs |
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.
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.
CommentsComment 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
//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.
Examplei=0;i++;
Previous HTML and JavaScript |
Contents | Next Dialogs |