Nęste
Forrige
Oversigt
JavaScript "Core Language" serie, Planche nr. 16
Kursus Indhold

Aritmetiske operatorer

Operator Description Example

%
(Modulus)

Binary operator. Returns the integer remainder of dividing the two operands.

12 % 5 returns 2.

++
(Increment)

Unary operator. Adds one to its operand. If used as a prefix operator (++x), returns the value of its operand after adding one; if used as a postfix operator (x++), returns the value of its operand before adding one.

If x is 3, then ++x sets x to 4 and returns 4, whereas x++ sets x to 4 and returns 3.

--
(Decrement)

Unary operator. Subtracts one to its operand. The return value is analogous to that for the increment operator.

If x is 3, then --x sets x to 2 and returns 2, whereas x++ sets x to 2 and returns 3.

-
(Unary negation)

Unary operator. Returns the negation of its operand.

If x is 3, then -x returns -3.


© 1999 BLA*net - Leif E. Andersen, leander@blanet.dk