About This Product
Metachecker.net | TrafficChecker.net | RankChecker.net
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet


Inserting Your Code.

Where do your JavaScript codes go? Well, basically anywhere inside the <html> tags of your page. The beginning of your code begins with <script> and ends with </script>

<html>
<head><title>This is an example page</title></head>
<body>
Welcome to the JavaScript course!
<script language="JavaScript">
<!--
document.write("Hi there. This text is written using JavaScript!")
//-->
</script>
</body>
</html>

Output: Hi there. This text is written using JavaScript!

As you can see, we began our script with the tag <script language="JavaScript"> The part in orange is purely optional, but you should include them to remind yourself-and others that you are using JavaScript now. The second and next to last lines of the above example are <!-- and //-->, which are the comment tags. These tags should ALWAYS be included to help hide your code against older browsers of both Netscape and IE. If you don't include them, and someone is using an old browser, the browser will just "dump" all your code as text onto the screen, in other words, not a pretty sight! The only "functional part" of this script is the document.write(".......") part. It basically writes to the page whatever you put inside the quotation marks. Don't worry so much about why this is so yet, we will discuss this in detail later. We end this entire code with </script> This terminates your script, and brings you back to html.

Like html, you can insert comments in your JavaScript codes. Comments are ignored by the browser, and only used as reminder or documentation for your code. To basic syntax of inserting comments is either:

//

for single-lined comments, or

/*

.......*/

for multiple ones.

For example:

<script language="JavaScript">
<!--

//this script does nothing and is useless!
/*Hay, don't involve me
in this!*/
//-->
</script>

Ok, we are now ready to proceed to some real programming!

JavaScript, like many programming languages, relies on objects, functions, and event handlers to create workable programs.   If you know absolutely nothing about these technical terms and how to use them, don't worry. By the time we're through with this tutorial, you will.

 

 

What is JavaScript

JavaScript is a scripting language designed for adding interactivity to HTML pages. The language was first implemented by Netscape Communications in Netscape Navigator 2 beta (1995). JavaScript is different from the Java language (developed at Sun Microsystems). However, the two languages can interoperate well.

JavaScript programs, or scripts, are usually embedded directly in HTML files. The script executes when the user's browser opens the HTML file. (There is also server-side JavaScript, but it's beyond the scope of this FAQ collection.)

JavaScript is an interpreted language. This means that scripts execute without preliminary compilation, i.e. without conversion of the script text into a system-dependent machine code. The user's browser interprets the script, that is, analyzes and immediately executes it. JavaScript is supported by the following browsers:

  • Netscape Navigator (beginning with version 2.0)
  • Microsoft Internet Explorer (beginning with version 3.0)
  • Any other browser/product whose vendor licensed or implemented JavaScript interpreter (for example, Opera).

Thus, most Internet users today have browsers that support JavaScript. That's why JavaScript is one of the most popular tools for adding interactive features to Web pages.

 

 

JavaScript Comments

JavaScript supports three different types of comments:
  1. Multiple-line C-style comments. Everything between /* and */ is a comment, for example:
    /* This is a comment */
    /* C-style comments can span
    as many lines as you like,
    as shown in this example */
    
  2. One-line comments of C++ style. These comments begin with // and continue up to the next line break:
    // This is a one-line comment
    
  3. One-line comments with the HTML comment-opening sequence (<!--). Note that the JavaScript interpreter ignores the closing characters of HTML comments (-->). Consider this example:
    <!-- This is treated as a one-line JS comment
    <!-- It works just like a comment beginning with //
    <!-- --> This is also a one-line JS comment
    <!-- --> because JS ignores the closing characters
    <!-- --> of HTML-style comments
    
    HTML-style comments are not usually found in the middle of JavaScript code. (The // comments are simpler and easier to read.) However, it is strongly recommended to use HTML comments for hiding JavaScript code from old browsers.