JavaScript SE: APPENDIX D Copyright ©1996, Que Corporation. All rights reserved. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 West 103rd Street, Indianapolis, IN 46290 or at support@mcp.com.

Notice: This material is excerpted from Special Edition Using JavaScript, ISBN: 0-7897-0789-6. The electronic version of this material has not been through the final proof reading stage that the book goes through before being published in printed form. Some errors may exist here that are corrected before the book is published. This material is provided "as is" without any warranty of any kind.


APPENDIX D - JavaScript Commands and Grammar

Finding information on programming in JavaScript can be a bit like looking for the Holy Grail. Between Netscape's site, 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.

JavaScript Statements

The statements used to control program flow in JavaScript 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 all statements. Since JavaScript 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 */.

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 for all of properties of an object:

for (variable in object) {
statements...
}

For each property, it executes the statement block.

function

Declares a JavaScript 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 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 an 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.

JavaScript Objects

JavaScript 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".

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 JavaScript relating to the current open Navigator window. New windows and frames can also be created.

Reserved Words

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

Color Values

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


Color Values
Color/string literalRedGreenBlue
aliceblueF0F8FF
antiquewhiteFAEBD7
aqua00FFFF
aquamarine7FFFD4
azureF0FFFF
beigeF5F5DC
bisqueFFE4C4
black000000
blanchedalmondFFEBCD
blue0000FF
blueviolet8A2BE2
brownA52A2A
burlywoodDEB887
cadetblue5F9EA0
chartreuse7FFFA0
chocolateD2691E
coralFF7F50
cornflowerblue6495ED
cornsilkFFF8DC
crimsonDC143C
cyan00FFFF
darkblue00008B
darkcyan008B8B
darkgoldenrodB8860B
darkgrayA9A9A9
darkgreen006400
darkkhakiBDB76B
darkmagenta8B008B
darkolivegreen556B2F
darkorangeFF8C00
darkorchid9932CC
darkred8B0000
darksalmonE9967A
darkseagreen8FBC8F
darkslateblue483D8B
darkslategray2F4F4F
darkturquoise00CED1
darkviolet9400D3
deeppinkFF1493
deepskyblue00BFFF
dimgray696969
dodgerblue1E90FF
firebrickB22222
floralwhiteFFFAF0
forestgreen228B22
fuchsiaFF00FF
gainsboroDCDCDC
ghostwhiteF8F8FF
goldFFD700
goldenrodDAA520
gray808080
green008000
greenyellowADFF2F
honeydewF0FFF0
hotpinkFF69B4
indianredCD5C5C
indigo4B0082
ivoryFFFFF0
khakiF0E68C
lavenderE6E6FA
lavenderblushFFF0F5
lawngreen7CFC00
lemonchiffonFFFACD
lightblueADD8E6
lightcoralF08080
lightcyanE0FFFF
lightgoldenrodyellowFAFAD2
lightgreen90EE90
lightgreyD3D3D3
lightpinkFFB6C1
lightsalmonFFA07A
lightseagreen20B2AA
lightskyblue87CEFA
lightslategray778899
lightsteelblueB0C4DE
lightyellowFFFFE0
lime00FF00
limegreen32CD32
linenFAF0E6
magentaFF00FF
maroon800000
mediumaquamarine66CDAA
mediumblue0000CD
mediumorchidBA55D3
mediumpurple9370DB
mediumseagreen3CB371
mediumslateblue7B68EE
mediumspringgreen00FA9A
mediumturquoise48D1CC
mediumvioletredC71585
midnightblue191970
mintcreamF5FFFA
mistyroseFFE4E1
moccasinFFE4B5
navajowhiteFFDEAD
navy000080
oldlaceFDF5E6
olive808000
olivedrab6B8E23
orangeFFA500
orangeredFF4500
orchidDA70D6
palgoldenrodEEE8AA
palegreen98FB98
paleturquoiseAFEEEE
palevioletredDB7093
papayawhipFFEFD5
peachpuffFFDAB9
peruCD853F
pinkFFC0CB
plumDDA0DD
powderblueB0E0E6
purple800080
redFF0000
rosybrownBC8F8F
royalblue4169E1
saddlebrown8B4513
salmonFA8072
sandybrownF4A460
seagreen2E8B57
seashellFFF5EE
siennaA0522D
silverC0C0C0
skyblue87CEEB
slateblue6A5ACD
slategray708090
snowFFFAFA
springgreen00FF7F
steelblue4682B4
tanD2B48C
teal008080
thistleD8BFD8
tomatoFF6347
turquoise40E0D0
violetEE82EE
wheatF5DEB3
whiteFFFFFF
whitesmokeF5F5F5
yellowFFFF00
yellowgreen9ACD32


Internet & New Technologies Home Page - Que Home Page
For technical support for our books and software contact support@mcp.com
© 1996, Que Corporation