TechieDrill Your World Of Technical Tutorials

Javascript Tutorial – 2 – Basic Syntax

11.09.2009 · Posted in JavaScript

To download this you tube video, Click Here

To everyone welcome to your second JavaScript tutorial, In this tutorial we are actually going to be writing our first JavaScript. So go ahead and open your notepad and I’m using notepad plus. And usually when you write JavaScript in a website that usually goes in a Head section or the Body Section of a website but just because we are learning how to write basic scripts I’m just going to be writing of nothing else, Just plain JavaScript and you can do this just fine. So lets go ahead and start writing our first JavaScript. Now any JavaScript code to write has to go between two script tags – Beginning tag and a End tag. Beginning tag looks like this

And any code that we create goes right in between this two tags.
Lets go and create the first script.
Always to write a basic script to output text on the screen
To do it in JavaScript
document.write();
The semicolon says that its the end of the line.
Anything we want to write goes between the parenthesis.
We can write a number between the parenthesis just displays out the number between the parenthesis.
If you want to write a text on the screen you have to include with a double or single quotes.
And one thing you cannot do is include text in no parenthesis or one double and one single quotes.
You will either get a blank screen or a error message will pop up.
Always make sure when you are working with text you enclose it with similar quotes.
Besides the document.write() there is an other way to output text which is called the alert syntax.
alert();
Anything we are going to write in alert, on our browser there will be a box pop up where the text will be in the pop up message where we should click OK to continue. For displaying numbers in the alert bow the rules are the same as similar to the document.write syntax. For numbers you don’t enclose it in quotes.

So now that we covered is to how to write a basic text on the screen as well as the basic numbers in how to enclose everything in a script tag . Next lesson we are going to go with little more useful – variables. So study this tutorial and learn how to output text on the screen and then watch my next tutorial.

Leave a Reply

You must be logged in to post a comment.