JavaScript
  Home arrow JavaScript arrow Page 6 - 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 
Sun Developer Network 
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 / 16
    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 - White Spaces and Case Sensitivity


    (Page 6 of 6 )

    White spaces are the spaces, tabs and line breaks that you use to improve your code readability. We could write the script in the example as follows:

    var firstValue = 10;var secondValue = 23;var result = firstValue + secondValue;
    document.write("The total of adding firstValue and secondValue = ");document.write(result);

    We have written three statements in first line and two statements in the second line. If you saved the code like this it will be executed in the same way. So white spaces are used to make your code look better and organized. You can't use white spaces inside an identifier, so you can't write the identifiers in our example as follows:

    <script language="JavaScript" type="text/javascript">
    var first Value = 10;
    var second Value = 23;
    var result = first Value + second Value;
    document.write("The total of adding firstValue and secondValue = ");
    document.write(result);
    </script>

    Replace the <script> block of the Web page with the above one and save the page. When you load it into IE and Firefox you will get the following error messages, respectively:

    These error messages tell us that the interpreter expects a semicolon after the first, because it considers it an identifier for a variable.

    Javascript keywords and identifiers are case-sensitive, which means that the identifier firstValue is not the same as FIRSTVALUE or FirstValue. They are different in their capitalization, and to the Javascript interpreter they are not the same, so they can be used as identifiers for different variables. Because of that, if you defined your variable as firstValue, and somewhere in the script you use FirstValue, you will get an error message, as with the following code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Hello World</title>
    <script language="JavaScript" type="text/javascript">
    var firstValue = 10;
    var secondValue = 23;
    var result = FirstValue + secondValue;
    document.write("The total of adding firstValue and secondValue = ");
    document.write(result);
    </script>
    </head>
    <body>

    </body>
    </html>

    When you save this file and load it into your browser, you will get the following Error Messages in IE 6 and Firefox 1.3:

    You get the Error: FirstValue is not defined, because Javascript is case-sensitive. We have declared the variable as firstValue, which is different from FirstValue, as we have said.

    Actually, there is a problem that you will encounter while you are programming, which is the casing style you use for your identifiers. There are two casing conventions used among programmers, Pascal casing and camel casing. Pascal casing states that all the words in your identifier begin with a capital letter, and there's no character that separates the words. For example, the identifiers FirstValue, SecondValue, and Result all display valid Pascal casing.

    Camel casing states that the first word of your Identifier begins with a small letter, the following words in the Identifier begin with a capital letter, and there are no characters that separate the words. We will use the camel casing for variable identifiers; we will talk about variables and data types in detail in the next article.

    So the example contains comments, keywords, identifiers and statements (plus other things which we don't need to know now). It simply declares two memory locations, stores some values there, then add them, puts the result in a third variable, and writes it to the Web page. I will take you step-by-step through the various examples in thsi article series, so you won't find any difficulties.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT