About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets


Arithmetic Operations

Question: What arithmetic operations are supported in JavaScript?

Answer: JavaScript supports the following arithmetic operations (which you can group in brackets to form more complex expressions):

Unary operations have one argument (in the following examples, the argument is a):

-a   // change the sign of a
~a   // bitwise NOT a
++a  // add 1 to a (before using a)
a++  // add 1 to a (after using a)
--a  // subtract 1 from a (before using a)
a--  // subtract 1 from a (after using a)

Binary operations operations have two arguments (in the following examples, the arguments are a and b):

a * b    // multiply a by b
a / b    // divide a by b
a % b    // find the remainder of division of a by b
a + b    // add a and b
a - b    // subtract b from a
a & b    // bitwise a AND b
a | b    // bitwise a OR b
a ^ b    // bitwise a XOR b

Shifts are the following operations:

a << b   // shift a by b bits to the left
         // (padding with zeros)
a >> b   // shift a by b bits to the right
         // (copying the sign bit)
a >>> b  // shift a by b bits to the right 
         // (padding with zeros)

BackBack