JavaScript
  Home arrow JavaScript arrow Page 2 - JavaScript Operators
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

JavaScript Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-11-05

    Table of Contents:
  • JavaScript Operators
  • Arithmetic Operators
  • Assignment Operators
  • Add and Assign
  • Comparison Operators
  • Logical Captain?

  • 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


    JavaScript Operators - Arithmetic Operators


    (Page 2 of 6 )

    We've been working with Arithmetic operators since we were children. In JavaScript they work pretty much the same way they did then. Observe:


    <html>

    <body>

    <script type="text/Javascript">


    var youweigh = 200

    var yourmommaweighs = 400

    var linebreak = "<br/>"


    document.write("Your weight: ")

    document.write(linebreak)

    document.write(youweigh)

    document.write(linebreak)

    document.write("Your mother weighs: ")

    document.write(linebreak)

    document.write(yourmommaweighs)

    totalweight=youweigh + yourmommaweighs

    document.write(linebreak)

    document.write("Your total weight is: ")

    document.write(linebreak)

    document.write(totalweight)

    </script>

    </body>

    </html>

    The above code insults your mother. Or maybe it doesn't. I mean if she weighs more than four hundred pounds, I guess it could be considered a compliment. At any rate, the above code assigns two variables a value. First, a variable named youweigh is assigned the value 200. Then a variable named yourmommaweighs is assigned the value 400. The program then goes through a process of printing out first the amount you weigh, and then the amount your mother weighs. Then, at the end, it uses the + operator to add the two weights, and print out your combined weight. The result of running the above code:

      Your weight:

      200

      Your mother weighs:

      400

      Your total weight is:

      600

    A Note about the Modulus

    For a while I found the Modulus to be confusing. No one ever adequately described what it did or what it was, despite the fact that it is very simple to define. Basically, modulus returns the remainder in division. Like so:


    <html>

    <body>

    <script type="text/Javascript">


    var valueone = 5

    var valuetwo = 2

    var linebreak = "<br/>"


    modresult = 5 % 2

    document.write(modresult)

    </script>

    </body>

    </html>

    The above code takes the variable valueone, assigns it the value of five, then takes the variable valuetwo and assigns it the value of two. Finally, we store the modulus in modresult, and print it. Since 5 / 2 equals 2 with a remainder of 1, we end up printing the 1 (the remainder or modulus).

    More JavaScript Articles
    More By James Payne


       · In this article we discuss Javascript Operators and how to use them to manipulate...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - 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...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





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