Introduction to Javascript programming

Sep 12, 2007 17:03 GMT  ·  By

Javascript is a language that provides you a simple code syntax and allows you to create scripts that the only thing they need to run is a javascript enabled web browser. In order to create and test a script you must have only a text editor and a modern web browser that is javascript enabled. The main advantage of this language is that it not require a compiler in order to run a certain script. You can create various applications (from simple to complex) that will run on client side, for example image galleries, from validation scripts, content rotators, text editors and even web browsers. You can begin to learn Javascript by understanding the main structure of a script:

code
My first Javascript

document.write("This is my first javascript")
document.write("
")
document.write(Math.random())
Copy and paste this code in a new Notepad window, then save it as html document. Open the page in a web browser and see the results. The javascript is delimited by the script tag. In this case the script will output in the body of your html web page the text "This is my first javascript" (without quotes). This action is caused by the document.write command. In the next line, as you see, Javascript outputs html code for creating a new line in document. On the new line a random number between 0 and 1 is generated by the Math object.

As you seen, Javascript allows you to create object oriented applications. Object oriented programming deals with objects, methods and properties. In this script, the document represents the object and the method of outputting text is the write command. Javascript can be employed to perform various simple math calculations. For example the Math object has many methods that will allow you to rapidly find out the result of various operations, generate random numbers (Math.random) and more.

You can extend the Javascript functionality by defining new functions in which you will use variables. Javascript can also be used as external file to the HTML document. Javascript is also used with server side programming languages (PHP) as a complementary tool. The necessity of Javascript usage is proven by the amount of various web applications in which Javascript is present. You should try to begin with the basics, given the fact that this was a very short introduction to Javascript language synthax and usage.