Appendix C

JScript Commands and Grammar


CONTENTS

Finding information on programming in JScript can be a bit like looking for the Holy Grail. Between Microsoft's and Netscape's sites, online tutorials, and examples, information seems to be everywhere but at your fingertips. So, here is the information you're looking for in one place, including statements, operators, and color values.

JScript Statements

The statements used to control program flow in JScript are similar to Java and C. A statement can span several lines if needed, or several statements can be placed on the same line. The important key to remember is that a semicolon must be placed between multiple statements on a single line. Because JScript is not strict in its formatting, you must provide the line breaks and indentation to make sure the code is readable and easy to understand later.

break.

Terminates the current for or while loop and passes control to the first statement after the loop.

comment.

Notes from the script author that are ignored by the interpreter. Single line comments are preceded by //. Multiple line comments begin with /* and end with */. Do not use HTML comment delimiters (<!-- and -->) with JScript code.

continue.

Passes control to the condition in a while loop and to the update expression in a for loop.

for.

Creates a loop with three optional expressions enclosed in parentheses and separated by semicolons, followed by a set of statements to be executed during the loop:

for( initialExpression; condition; updateExpression) {
statements...
}

The initial expression is used to initialize the counter variable, which can be a new variable declared with var. The condition expression is evaluated on each pass through the loop. If the condition is true, the loop statements are executed. The update expression is used to increment the counter variable.

for…in.

Iterates a variable over all the properties of an object:

for (var vtmp in object) {
statements...
}

For each property, it executes the statement block with vtmp set to the current property.

function.

Declares a JScript function with a name and parameters. To return a value, the function must include a return statement. A function definition cannot be nested within another function.

function name ([parameter] [...,parameter]) {
statements...
}

if…else.

A conditional statement that executes the first set of statements if the condition is true, and the statements following the else if false. If...else statements can be nested to any level.

if (condition) {
statements...
} [else {
 statements...
}]

return.

Specifies a value to be returned by a function.

return expression;

var.

Declares a variable and optionally initializes it to a value. The scope of a variable is the current function or-when declared outside a function-the current document.

var variableName [=value] [..., variableName [=value]]

while.

Repeats a loop while a conditional expression is true.

while (condition) {
statements...
}

with.

Establishes a default object for a set of statements. Any property references without an object are assumed to use the default object.

with (object) {
statements...
}

This statement is especially useful when applied to the Math object for a set of
calculations. For example:

with (Math) {
var Value1 = cos(angle);
var Value2 = sin(angle);
}

replaces:

{
var Value1 = Math.cos(angle);
var Value2 = Math.sin(angle);
}

Operator Precedence

Precedence refers to the order in which compound operations are computed. Operators on the same level have equal precedence. Calculations are computed from left to right on all binary operations beginning with the operators at the top of the list and working down.

call, member
.
[]
()
 
 
negation/increment
++
--
!
~
-
multiply/divide
*
/
%
 
 
addition/subtraction
+
-
 
 
 
shift
<<
>>
>>>
 
 
relational
<
>
<=
>=
 
equality
==
!=
 
 
 
bitwise AND
&
 
 
 
 
bitwise XOR
^
 
 
 
 
bitwise OR
|
 
 
 
 
logical AND
&&
 
 
 
 
logical OR
||
 
 
 
 
conditional
?:
 
 
 
 
assignment
=
op=
 
 
 
comma
,
 
 
 
 

JScript Objects

JScript is an object-oriented language, and as such, includes a set of built-in objects to represent the HTML document, especially form elements. Built-in objects can be accessed by both the client and server.

String.

Contains a string of characters.

Math.

Provides numerical constants and mathematical functions.

Date.

Stores a date in the number of milliseconds since 1/1/1970, 00:00:00, and returns a date string in the format "Thu, 11 Jan 1996 06:20:00 GMT."

Array.

Holds an array of elements.

Document.

The foundation object created with an HTML <BODY> tag and used to write other information to the page.

Form.

An object for gathering and echoing data, created by HTML <FORM> tags.

Window.

The highest precedence object accessible by JScript relating to the currently open browser window. New windows and frames can also be created.

Reserved Words

The following words cannot be used as user objects or variables in coding JScript. Not all are currently in use by JScript-they are reserved for future use.

Abstract int
boolean interface
break long
byte native
case new
catch null
char package
class private
const protected
continue public
default return
do short
double static
else super
extends switch
false synchronized
final this
finally throw
float throws
for transient
function true
goto try
if var
implements void
import while
in with
instanceof  

Color Values

Colors can be referenced in a variety of properties in two ways: by using the string literal or an RGB hexadecimal triplet formed by combining the three color values. For example, aliceblue is represented as F0F8FF.

Color/String Literal
Red
Green
Blue
aliceblue
F0
F8
FF
antiquewhite
FA
EB
D7
aqua
00
FF
FF
aquamarine
7F
FF
D4
azure
F0
FF
FF
beige
F5
F5
DC
bisque
FF
E4
C4
black
00
00
00
blanchedalmond
FF
EB
CD
blue
00
00
FF
blueviolet
8A
2B
E2
brown
A5
2A
2A
burlywood
DE
B8
87
cadetblue
5F
9E
A0
chartreuse
7F
FF
A0
chocolate
D2
69
1E
coral
FF
7F
50
cornflowerblue
64
95
ED
cornsilk
FF
F8
DC
crimson
DC
14
3C
cyan
00
FF
FF
darkblue
00
00
8B
darkcyan
00
8B
8B
darkgoldenrod
B8
86
0B
darkgray
A9
A9
A9
darkgreen
00
64
00
darkkhaki
BD
B7
6B
darkmagenta
8B
00
8B
darkolivegreen
55
6B
2F
darkorange
FF
8C
00
darkorchid
99
32
CC
darkred
8B
00
00
darksalmon
E9
96
7A
darkseagreen
8F
BC
8F
darkslateblue
48
3D
8B
darkslategray
2F
4F
4F
darkturquoise
00
CE
D1
darkviolet
94
00
D3
deeppink
FF
14
93
deepskyblue
00
BF
FF
dimgray
69
69
69
dodgerblue
1E
90
FF
firebrick
B2
22
22
floralwhite
FF
FA
F0
forestgreen
22
8B
22
fuchsia
FF
00
FF
gainsboro
DC
DC
DC
ghostwhite
F8
F8
FF
gold
FF
D7
00
goldenrod
DA
A5
20
gray
80
80
80
green
00
80
00
greenyellow
AD
FF
2F
honeydew
F0
FF
F0
hotpink
FF
69
B4
indianred
CD
5C
5C
indigo
4B
00
82
ivory
FF
FF
F0
khaki
F0
E6
8C
lavender
E6
E6
FA
lavenderblush
FF
F0
F5
lawngreen
7C
FC
00
lemonchiffon
FF
FA
CD
lightblue
AD
D8
E6
lightcoral
F0
80
80
lightcyan
E0
FF
FF
lightgoldenrodyellow
FA
FA
D2
lightgreen
90
EE
90
lightgray
D3
D3
D3
lightpink
FF
B6
C1
lightsalmon
FF
A0
7A
lightseagreen
20
B2
AA
lightskyblue
87
CE
FA
lightslategray
77
88
99
lightsteelblue
B0
C4
DE
lightyellow
FF
FF
E0
lime
00
FF
00
limegreen
32
CD
32
linen
FA
F0
E6
magenta
FF
00
FF
maroon
80
00
00
mediumaquamarine
66
CD
AA
mediumblue
00
00
CD
mediumorchid
BA
55
D3
mediumpurple
93
70
DB
mediumseagreen
3C
B3
71
mediumslateblue
7B
68
EE
mediumspringgreen
00
FA
9A
mediumturquoise
48
D1
CC
mediumvioletred
C7
15
85
midnightblue
19
19
70
mintcream
F5
FF
FA
mistyrose
FF
E4
E1
moccasin
FF
E4
B5
navajowhite
FF
DE
AD
navy
00
00
80
oldlace
FD
F5
E6
olive
80
80
00
olivedrab
6B
8E
23
orange
FF
A5
00
orangered
FF
45
00
orchid
DA
70
D6
palegoldenrod
EE
E8
AA
palegreen
98
FB
98
paleturquoise
AF
EE
EE
palevioletred
DB
70
93
papayawhip
FF
EF
D5
peachpuff
FF
DA
B9
peru
CD
85
3F
pink
FF
C0
CB
plum
DD
A0
DD
powderblue
B0
E0
E6
purple
80
00
80
red
FF
00
00
rosybrown
BC
8F
8F
royalblue
41
69
E1
saddlebrown
8B
45
13
salmon
FA
80
72
sandybrown
F4
A4
60
seagreen
2E
8B
57
seashell
FF
F5
EE
sienna
A0
52
2D
silver
C0
C0
C0
skyblue
87
CE
EB
slateblue
6A
5A
CD
slategray
70
80
90
snow
FF
FA
FA
springgreen
00
FF
7F
steelblue
46
82
B4
tan
D2
B4
8C
teal
00
80
80
thistle
D8
BF
D8
tomato
FF
63
47
turquoise
40
E0
D0
violet
EE
82
EE
wheat
F5
DE
B3
white
FF
FF
FF
whitesmoke
F5
F5
F5
yellow
FF
FF
00
yellowgreen
9A
CD
32