JavaScript Composition

Javascript Composition

Scripts of JavaScript lies in the HTML document.
The code will not be visible from in your navigator window, because between the tags (if you know HTML surely you must know this term) who ordered the navigator to a particular treat that script is the JavaScript. An example of a script that shows that the script is the JavaScript is as follows :

<SCRIPT Language="JavaScript">
put your code here

Put comments
You can put comments in order to make the scripts are not executed. It is often the old version navigator, before any JavaScript, do not recognize these tags and will miss it for the reading. Examples of the above code will not be visible in our navigator, but he will display a warning window (a dialog box) because the script is incomplete and will damage the HTML document you created with good. For those reasons, we add a comment tags so that scripts do not read the script, but in reading the comments and will not be executed as a program. Examples are as follows:

<SCRIPT Language="JavaScript">
put your code here
As in many other programming languages, it is advisable to add comments in the script or program code that we make. Usefulness among other are:
  • Reminds us be part of a special section within the script, if we want to change something in it, maybe a few months later and we've forgotten with the detail and flow of these scripts.
  • Getting people who do not understand your script, be understood with the instructions you made that will guide through the comments, unless you do not want to share program you have

To write a comment in JavaScript, we can use the same way with the existing rules in language C / C++ or Java.

  • To write comments in a row we use a double slash character.
// All the characters in the back // not executed
  • To write comments that consist of several lines we use the characters /* and */ 

Note the difference to the HTML comment tags (such as to hide scripts from older versions of some browsers) and JavaScript comment tags (for documentation purposes scripts).

Examples of JavaScript programs

In the following example is an example of JavaScript scripts within an HTML document, here we
will create a program to display a dialog box when you open an HTML document:
Example <TITLE> Javascript Program </ TITLE>
</ HEAD>
<script Language="JavaScript">
<! -
alert ("Hello!");
// ->
</ BODY>
</ HTML>


Post a Comment