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.
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.
Terminates the current for or while loop and passes control to the first statement after the loop.
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.
Passes control to the condition in a while loop and to the update expression in a for loop.
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.
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.
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... }
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... }]
Specifies a value to be returned by a function.
return expression;
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]]
Repeats a loop while a conditional expression is true.
while (condition) { statements... }
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); }
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 | |||||
comma |
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.
Contains a string of characters.
Provides numerical constants and mathematical functions.
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."
Holds an array of elements.
The foundation object created with an HTML <BODY> tag and used to write other information to the page.
An object for gathering and echoing data, created by HTML <FORM> tags.
The highest precedence object accessible by JScript relating to the currently open browser window. New windows and frames can also be created.
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 |
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 | |||
aliceblue | |||
antiquewhite | |||
aqua | |||
aquamarine | |||
azure | |||
beige | |||
bisque | |||
black | |||
blanchedalmond | |||
blue | |||
blueviolet | |||
brown | |||
burlywood | |||
cadetblue | |||
chartreuse | |||
chocolate | |||
coral | |||
cornflowerblue | |||
cornsilk | |||
crimson | |||
cyan | |||
darkblue | |||
darkcyan | |||
darkgoldenrod | |||
darkgray | |||
darkgreen | |||
darkkhaki | |||
darkmagenta | |||
darkolivegreen | |||
darkorange | |||
darkorchid | |||
darkred | |||
darksalmon | |||
darkseagreen | |||
darkslateblue | |||
darkslategray | |||
darkturquoise | |||
darkviolet | |||
deeppink | |||
deepskyblue | |||
dimgray | |||
dodgerblue | |||
firebrick | |||
floralwhite | |||
forestgreen | |||
fuchsia | |||
gainsboro | |||
ghostwhite | |||
gold | |||
goldenrod | |||
gray | |||
green | |||
greenyellow | |||
honeydew | |||
hotpink | |||
indianred | |||
indigo | |||
ivory | |||
khaki | |||
lavender | |||
lavenderblush | |||
lawngreen | |||
lemonchiffon | |||
lightblue | |||
lightcoral | |||
lightcyan | |||
lightgoldenrodyellow | |||
lightgreen | |||
lightgray | |||
lightpink | |||
lightsalmon | |||
lightseagreen | |||
lightskyblue | |||
lightslategray | |||
lightsteelblue | |||
lightyellow | |||
lime | |||
limegreen | |||
linen | |||
magenta | |||
maroon | |||
mediumaquamarine | |||
mediumblue | |||
mediumorchid | |||
mediumpurple | |||
mediumseagreen | |||
mediumslateblue | |||
mediumspringgreen | |||
mediumturquoise | |||
mediumvioletred | |||
midnightblue | |||
mintcream | |||
mistyrose | |||
moccasin | |||
navajowhite | |||
navy | |||
oldlace | |||
olive | |||
olivedrab | |||
orange | |||
orangered | |||
orchid | |||
palegoldenrod | |||
palegreen | |||
paleturquoise | |||
palevioletred | |||
papayawhip | |||
peachpuff | |||
peru | |||
pink | |||
plum | |||
powderblue | |||
purple | |||
red | |||
rosybrown | |||
royalblue | |||
saddlebrown | |||
salmon | |||
sandybrown | |||
seagreen | |||
seashell | |||
sienna | |||
silver | |||
skyblue | |||
slateblue | |||
slategray | |||
snow | |||
springgreen | |||
steelblue | |||
tan | |||
teal | |||
thistle | |||
tomato | |||
turquoise | |||
violet | |||
wheat | |||
white | |||
whitesmoke | |||
yellow | |||
yellowgreen |