JavaScript
  Home arrow JavaScript arrow Page 4 - The Power of Javascript: Operators conclud...
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: Operators concluded
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2005-08-02

    Table of Contents:
  • The Power of Javascript: Operators concluded
  • Logical Operators Example
  • The Operator typeof
  • The Void Operator
  • Operator Precedence and Associativity

  • 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: Operators concluded - The Void Operator


    (Page 4 of 5 )

    The void operator is used to set to execute the expression without returning any values. Let's take a look:

    <!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 aNumber = void 1; 
          document.write("aNumber data type = " + aNumber + "<br>");
        </script>
      </head>
      <body>
      </body>
    </html>

    Save and load this code and you will notice that the variable aNumber is assigned the value undefined.

    The Ternary Operator :?

    This operator is called the ternary conditional operator. To understand why they call it conditional you need to take a look at its three operands. The first operand is a boolean expression. When it evaluates to true the statement in the second operand gets executed, and when it evaluates to false the statement in the third operand get executed. It takes the form

    boolean expression ? the true statement : the false statement ;

    Note that we can't put the semicolon after the second operand because the colon symbol (:) in the operator separates the second and the third operand. If you put in the semicolon you will get an error; you need to put a semicolon at the third operand. Let's take a look at an example:

    <!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 x = 8;
          x < 10 && x > 5 ? document.write("Yes, x is less than 10") : document.write("No, x is no less than 10");
        </script>
      </head>
      <body>
      </body>
    </html>

    Save and load the above code and you will get this result.

    It's very simple, the expression x < 10 && x > 5 is evaluated, and if it's true then the second operand is executed, which writes to the Web page the string "Yes, x is less than 10." If the expression evaluated to false, then the third operand is executed (not the second one).

    More JavaScript Articles
    More By Michael Youssef


     

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