This article aims to give an introduction to simple and not extremely formal scripting language which have been established as one of the foundations of the entire web application. You’ve probably heard this name, but have no idea what it is or you may have used it but have no basic idea about this. Then this article is made for you to understand how it works and how to make your first script in this language.
|Scripting Language||Programming Language||Markup Language|
|As mentioned before, it’s interpreted line by line by an interpreter, and remains as it is, no change occurs||It’s human readable language, machines don’t understand it, hence it’s compiled to binary code “0s and 1s” so it can be understood by machines and run.||Consider that you want to organize your document, so all what you need to do it to markup it. Exactly that’s why markup languages do, it’s designed to transform raw text into structured documents by adding descriptive tags to the text.|
When we access a web page, we have a sequence of events, or rather a flow of communication between our computer and the server where the page, see figure 1.
Figure 1: Example of communication between the user’s computer and the Web server
The figure gives us an idea of what happens when we type the address www.javabeat.net, for example. Let me explain:
- You type the address into your browser www.javabeat.net, it will be communicated to the server about this page and asking relevant files to be sent;
- Your computer receives this code, interprets it, and if necessary, requests pictures, media files and more that are being referenced in the HTML received.
- Can dynamically generate HTML elements in runtime
- Can read and change contents of HTML elements
- Can Handle Events
- Is used for Client side validation
- Can detect visitor browser and settings
- Can create cookies
- Can directly access files on the web server
- Can directly access files on the user’s system
- implicitly :Means that it can be written in one of two places in the web page.
- In Head Section: which will be loaded before the rest of the document and if it’s written in a function it will be loaded upon request.
- In Body section: which will be loaded in it’s turn on the page .
You can write any number of scripts inside the page, code is written between tag
- Explicitly: Means that code will be written in separate file and linked to the desired page. Code is written in separate file with .js extension and is included in the head of the web page example :
Listing 1: Source code of the example constructed[java] <html>
<title> Article 01 – Hello World </title>
alert (‘Hello World!’);
Save this file as index.html and open in any of your browser, result would be as in the figure 2 below:
Figure 2: Output
- Use “;” after each statement
- take care of opening and closing of TAG <script>.
Well, let me explain the source code of our above example.