JavaScript
  Home arrow JavaScript arrow Page 5 - 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 - Identifiers


    (Page 5 of 6 )

    When you declare a variable in the memory, how will you refer to it? You use an identifier to refer to your variable. An identifier is simply a name that is used to reference a variable (or as we are going to see, other programming constructions like functions), so in our example we have three Identifiers that refer to our three variables:

    var firstValue = 10;

    var secondValue = 23;

    var result = firstValue + secondValue;

    The identifier firstValue is the name of the variable that stores the value 10 in the memory. The identifier secondValue is the name of the variable that stores the value 23 in the memory. The result is the name of the variable that stores the value 10 (of the variable firstValue) plus the value 23 (of the variable secondValue). So we use identifiers to name our programming constructions.

    Note that you declare a variable using the keyword var followed by the variable identifier. We will talk about variables and data types in the next article.

    You can't use var as an identifier because it's a keyword that has been reserved by the Javascript language, so it will produce errors and problems when used. Let's try to use the keyword else as an identifier for a variable.

    <!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 else = 134;
    document.write(else);
    </script>
    </head>
    <body>

    </body>
    </html>

    We have used the var keyword to declare a variable, followed by the variable identifier, then its value (134). Save the file and load it in your IE Browser. You will get the following error message:

    Error: Expected identifier means that the Javascript interpreter was not able to find the variable's identifier. We used the keyword var so the interpreter would understand that we need to declare a variable. Next we used else as the identifier, but the interpreter knows that else is a reserved keyword so it tells you that it expected an identifier.

    If you run this code in Firefox you will get a better error message. Open the Web page with Firefox. Go to Tools, then choose Javascript Console, and you will get the following error message to the console:

    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 1 Hosted by Hostway
    Stay green...Green IT