Home arrow JavaScript arrow Page 4 - JavaScript Operators
JAVASCRIPT

JavaScript Operators


You can't do much with a programming language without operators. JavaScript is no exception. So this article will introduce you to JavaScript operators and what you can do with them.

Author Info:
By: James Payne
Rating: 4 stars4 stars4 stars4 stars4 stars / 3
November 05, 2007
TABLE OF CONTENTS:
  1. · JavaScript Operators
  2. · Arithmetic Operators
  3. · Assignment Operators
  4. · Add and Assign
  5. · Comparison Operators
  6. · Logical Captain?

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
JavaScript Operators - Add and Assign
(Page 4 of 6 )

The add and assign operator works like this: a = a + y is the same as writing a += y. Or like this:


<HTML>

<HEAD>

<script type="text/Javascript">

a=10

y=5

line = '<br>'

document.write(a)

document.write(line)

document.write(y)

document.write(line)

a += y

document.write(a)

</SCRIPT>

</HEAD>

</HTML>

The above code prints out:

  10
  5
  15

First we assigned a value to a (10), then we assigned a value to y (5) and printed them both out with a line break (which we cleverly stored in a variable). We then added the two variables together using the += operator, and printed the new value of the variable a.

It works the same way with the other arithmetic assignment operators as well. Had I used *=, the final value of a would have been 50. If I had used the /= it would have been 2, and had I used the %= it would have been 0, since there is no remainder in the expression 10 / 5.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials