JavaScript
  Home arrow JavaScript arrow Page 2 - The Power of Javascript: Basic Concepts
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

The Power of Javascript: Basic Concepts
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 19
    2005-07-05

    Table of Contents:
  • The Power of Javascript: Basic Concepts
  • Javascript Comments
  • Javascript Statements
  • Keywords
  • Identifiers
  • White Spaces and Case Sensitivity

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Power of Javascript: Basic Concepts - Javascript Comments


    (Page 2 of 6 )

    Comments are descriptive text that is ignored by the interpolator, which we use to comment our scripts. Comments in Javascript take two forms. The first form is a comment that takes one line. You use two forward slashes for it (//) followed by your comment, like the following:

    // the firstValue is a location in memory that
    // stores the value 10

    Note that in this example the comment has spanned two lines, so we needed two forward slashes at the beginning of each line. As you can see, the whole line is used for the comment, but you can put your comment after the Javascript code line, as in the following line:

    var secondValue = 23; // the secondValue is another location in memory that stores the value 23

    The second form of the comment you can use is the multiple line comment, which you define by using a forward slash followed by an asterisk (/*), and end using an asterisk followed by a forward slash (*/). All of the lines between those symbols are considered a comment, like the following:

    /* Comments, Keywords, Identifiers,
    Case Sensitivity, White spaces and statements*/

    Also, it can be written like this:

    /*
    Comments, Keywords, Identifiers,
    Case Sensitivity, White spaces and statements
    */

    At first you may not appreciate the importance of including comments in your scripts, but when you gain enough experience to write complex Javascript, you definitely will need to comment. Imagine that you have written a very important script for your company's website and after one year your manager asked you to modify the functionality of the script to do something else. You will open your script and may ask yourself "Why did I write the script this way?" and find that you don't remember. You may spend many hours trying to understand why and how your wrote the code that way.

    To give another possible situation, say you wrote the script and after one year, while you are on vacation, your manager asked your co-programmer to modify this script. He will spend more hours than you to try to understand your code. So for you and for anyone else who might use your code, it's better to include comments in your scripts; that way, when you come back later you understand what's going on. You (or anyone else who needs to modify the code) can just read the scripts and comments and easily do what needs to be done.

    However, when you are done with your script, it's better to remove the comments from the Web page (to minimize the page size and thus save bandwidth). You can write your scripts and save them in a Javascript file (with the extension .js), and name it after the Web page or any other name to remind you that this script is written for that page. In this file you can comment your code as much as you want, then you can copy the script (without the comments) into the Web page.

    More JavaScript Articles
    More By Michael Youssef


     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT