Chapter 2 The DynaScript Language
This section describes the operators available in scripts.
Operators act on one or more expressions called operands. Operators can be either ternary, binary or unary: ternary operators act on three expressions, binary operators act on two expressions, and unary operators act on one.
For example, the addition operator is a binary operator, so the following is a valid expression:
x + y ;
The increment operator (which adds one to a number) is a unary operator, so the following is a valid expression:
x++ ;
The following arithmetic operators are provided:
Operator |
Description |
Binary or unary |
---|---|---|
+ |
addition |
binary |
- |
subtraction |
binary |
* |
multiplication |
binary |
/ |
division |
binary |
% |
modulo |
binary |
++ |
increment |
unary |
-- |
decrement |
unary |
- |
negation |
unary |
x++
++x
x = 56 ;
y = x-- ; // Sets y to 56 and decrements x to 55
y = --x ; // Decrements x to 55 and sets y to 55
The following conditional operator is provided:
Operator |
Description |
---|---|
? |
Conditional |
The ? operator is ternary, meaning that it acts on three expressions.
The ? operator evaluates to one of two values, based on a condition. An example of the ? operator is as follows:
(grade == "pass") ? "Excellent" : "Try again";
The following string operators are provided:
Operator |
Description |
---|---|
+ |
Concatenation |
+= |
Concatenation with assignment |
Comparison operators can also operate on strings, but the result is a Boolean value.
The following comparison operators are provided:
Operator |
Description |
---|---|
= = |
Equal to |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
<> |
Not equal to |
!= |
Not equal to |
These operators can act on numbers or strings,
and return a Boolean (logical) value of true
or false
.
Boolean operators operate on Boolean (logical) expressions. The following Boolean operators are provided:
Bitwise operators treat their operands as a set of bits (zeros and ones), rather than as decimal, hexadecimal, or octal numbers. Bitwise operators perform their operations on such binary representations, but they return standard numerical values.
The following bitwise operators are provided:
The delete operator may be used to delete a property from an object or to delete an element from an array. For example
delete x
Returns true if deletion is successful, false otherwise.
The void operator may be used to prevent an expression from returning a value. For example
void addVar
The void operator will evaluate its expression
and then returned undefined
.
The typeof operator may be used to return the datatype of an expression. For example
document.writeln( typeof(addVar) );
The typeof operator returns a string that can be one of number, string, Boolean, object, function or undefined.
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |