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


    (Page 3 of 6 )

    We worked with the "=" assignment operator when we went over variables. As the name suggests, assignment operators assign a value. Where they can get tricky is in the pre/post area. When you use an assignment variable in the position before the variable, it is added prior to the line being executed. When you use it after the variable, it is added afterward. Sound confusing? This should clear it up.

    <HTML>

    <HEAD>

    <script type="text/Javascript">

    a=10

    b=6

    document.write('Angelina Jolie is '+a+++', and in ten years will be an '+a)

    document.write('<BR>Jennifer Lopez is a '+--b+', and in ten years will be a '+b)

    </SCRIPT>

    </HEAD>

    </HTML>

    In the above sample I rated the current hotness and predicted future hotness of Angelina Jolie and Jennifer Lopez. As you can see, I don't think J-Lo is very hot. I used the increment (++) operator to increase the hotness of Angelina Jolie by one. Since the ++ appeared after the variable name, it prints 10 instead of eleven in the first part of the sentence, then it increments the value by one, and prints eleven at the end of the sentence. This is the result:

      Angelina Jolie is 10, and in ten years will be an 11
      Jennifer Lopez is a 5, and in ten years will be a 5

    If I had put the ++ at the beginning of the variable, it would have read this way:

      Angelina Jolie is 11, and in ten years will be an 11
      Jennifer Lopez is a 5, and in ten years will be a 5

    It works the same way with the - decrementing operator. As you can see in the J-Lo example, it subtracted 1 from the value of b prior to printing the variable.

    More JavaScript Articles
    More By James Payne


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

    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