IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
JavaScript
Search JavaScript Group:

Advanced
-Collapse +Expand JavaScript Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...JavaScript a...Language Ref...   Print This     
  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

KB100167



Assignment Operators

Operator
Description
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

Operator
Description
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

Operator
Description
Example
+

Adds two values together

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

Operator
Description
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?")

Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1261A1
Enter key:
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
24229
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2019 Prestwood IT Solutions.   [Security & Privacy]