I.T. Discussion Community!
 JavaScript
 JavaScript Group Home eMag: JavaScript E. WEEKLYLESSON MYGROUPSETTINGS
 Message Board
 JavaScript KB
 JavaScript To/From To/FromCODEGuides
 JavaScript Store PRESTWOODSTORE Store Home Buy JavaScript Items
 Members Only

Prestwood eMagazine

April Edition
Subscribe now! It's Free!

 ► KB ► Website Scri... ► JavaScript a... ► Language Ref...
From the August 2015 Issue of Prestwood eMag
 JavaScript Language Reference:JavaScript Operators
Posted 16 years ago on 3/19/2003 and updated 3/30/2008
Take Away: Javascript operators: assignment, comparison, computational, and logical.
Tags: JavaScript , operators

Assignment Operators

Example
=

Sets one value equal to another

age = 21
+=

Shortcut for adding to the current value.

age += 1
-=

Shortcut for subracting from the current value.

age -= 1
*=

Shortcut for multiplying the current value.

age *= 3
/=

Shortcut for dividing the current value.

age /= 3

Comparison Operators

Example
==

Returns a true value if the items are the same

age==21
!=

Returns a true value if the items are not the same

age!=21
>

Returns a true value if the item on the left is greater than the item on the right

age>21
>=

Returns a true value if the item on the left is equal to or greater than the item on the right

age>=21
<

Returns a true value if the item on the left is less than the item on the right

age<21
<=

Returns a true value if the item on the left is equal to or less than the item on the right

age<=21

Computational Operators

Example
+

counter+2
-

Subtracts one value from another

counter-2
*

Multiplies two values

counter*10
/

Divides the value on the left by the one on the right and returns the result

counter/2
++X

Increments the value, and then returns the result

++counter
X++

Returns the value, and then increments the value

counter++
--X

Decreases the value, and then returns the result

--counter
X--

Returns the value, and then decreases the value

counter--

Logical Operators

Example
&&

Looks at two expressions and returns a value of "true" if both expressions are true.

if day='friday'&&date=13 then alert("Are You Superstitious?")
||

Looks at two expressions and returns a value of "true" if either one -- but not both -- of the expressions are true.

if day='friday'&&date=13 then alert("Are You Superstitious?") else if day='friday'||date=13 then alert("Aren't you glad it isn't Friday the 13th?")

Share a thought or comment...

KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

 Visit Profile

 KB Article #100167 Counter 24136 Since 4/2/2008
-
 Contact Us! PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too! --Mike Prestwood
 Who's Online!