Appendix E
JavaScript Language
Reference
The first part of this reference is organized by object with properties and methods
listed by the object they apply to. The second part covers independent functions
in JavaScript not connected with a particular object, as well as operators in JavaScript.
The following codes are used to indicate where objects, methods, properties, and
event handlers are implemented:
The anchor Object [C|2|3|I]
The anchor object reflects an HTML anchor.
Property
- name A string value indicating the name of the anchor. [Not 2|3]
The applet Object [C|3]
The applet object reflects a Java applet included in a web page with
the APPLET tag.
Property
- name A string reflecting the NAME attribute of the APPLET tag.
The area Object [C|3]
The area object reflects a clickable area defined in an imagemap. area
objects appear as entries in the links array of the document object.
Properties
- n hash A string value indicating an anchor name from the URL.
- host A string value reflecting the host and domain name portion of the URL.
- hostname A string value indicating the host, domain name, and port number from
the URL.
- href A string value reflecting the entire URL.
- pathname A string value reflecting the path portion of the URL (excluding the
host, domain name, port number, and protocol).
- port A string value indicating the port number from the URL.
- protocol A string value indicating the protocol portion of the URL including
the trailing colon.
- search A string value specifying the query portion of the URL (after the question
mark).
- target A string value reflecting the TARGET attribute of the AREA
tag.
Event Handlers
The Array Object [C|3|I]
Provides a mechanism for creating arrays and working with them. New arrays are
created with arrayName = new Array() or arrayName = new Array(arrayLength).
Properties
Methods
The button Object [C|2|3|I]
The button object reflects a push button from an HTML form in JavaScript.
Properties
Methods
Event Handlers
The checkbox Object [c|2|3|I]
The checkbox object makes a checkbox in an HTML form available in JavaScript.
Properties
- n checked A Boolean value indicating whether the checkbox element is
checked.
- defaultChecked A Boolean value indicating whether the checkbox element was checked
by default (that is, reflects the CHECKED attribute).
- enabled A Boolean value indicating whether the checkbox is enabled. [Not 2|3]
- form A reference to the form object containing the checkbox. [Not 2|3]
- name A string value containing the name of the checkbox element.
- type A string value reflecting the TYPE attribute of the INPUT
tag. [Not 2|I]
- value A string value containing the value of the checkbox element.
Methods
Event Handlers
The combo Object [C|I]
The combo object reflects a combo field into JavaScript.
Properties
Methods
Event Handlers
The Date Object [C|2|3|I]
The Date object provides mechanisms for working with dates and times
in JavaScript. Instances of the object can be created with the syntax
newObjectName = new Date(dateInfo)
Where dateInfo is an optional specification of a particular date and can be one
of the following: "month, Chapter, year hours:minutes:seconds"
year, month, Chapter
- year, month, Chapter, hours, minutes, seconds
where the latter two options represent integer values.
If no dateInfo is specified, the new object will represent the current date and
time.
Property
- n prototype Provides a mechanism for adding properties to a Date
object. [Not 2]
Methods
- n getDate() Returns the Chapter of the month for the current Date
object as an integer from 1 to 31.
- getChapter() Returns the Chapter of the week for the current Date object as
an integer from 0 to 6 (where 0 is SunChapter, 1 is MonChapter, and so on).
- getHours() Returns the hour from the time in the current Date object
as an integer from 0 to 23.
- getMinutes() Returns the minutes from the time in the current Date object
as an integer from 0 to 59.
- getMonth() Returns the month for the current Date object as an integer
from 0 to 11 (where 0 is January, 1 is February, and so on).
- getSeconds() Returns the seconds from the time in the current Date object
as an integer from 0 to 59.
- getTime() Returns the time of the current Date object as an integer
representing the number of milliseconds since January 1, 1970 at 00:00:00.
- getTimezoneOffset() Returns the difference between the local time and GMT as
an integer representing the number of minutes.
- getYear() Returns the year for the current Date object as a two-digit
integer representing the year minus 1900.
- parse(dateString) Returns the number of milliseconds between January 1, 1970
at 00:00:00 and the date specified in dateString. dateString should take the following
format [Not I]:
Chapter, DD Mon YYYY HH:MM:SS TZN
- Mon DD, YYYY
- setDate(dateValue) Sets the Chapter of the month for the current Date object.
dateValue is an integer from 1 to 31.
- setHours(hoursValue) Sets the hours for the time for the current Date
object. hoursValue is an integer from 0 to 23.
- setMinutes(minutesValue) Sets the minutes for the time for the current Date
object. minutesValue is an integer from 0 to 59.
- setMonth(monthValue) Sets the month for the current Date object. monthValue
is an integer from 0 to 11 (where 0 is January, 1 is February, and so on).
- setSeconds(secondsValue) Sets the seconds for the time for the current Date
object. secondsValue is an integer from 0 to 59.
- setTime(timeValue) Sets the value for the current Date object. timeValue
is an integer representing the number of milliseconds since January 1, 1970 at 00:00:00.
- setYear(yearValue) Sets the year for the current Date object. yearValue
is an integer greater than 1900.
- toGMTString() Returns the value of the current Date object in GMT as
a string using Internet conventions in the form
- Chapter, DD Mon YYYY HH:MM:SS GMT
- toLocaleString() Returns the value of the current Date object in the
local time using local conventions.
- UTC(yearValue, monthValue, dateValue, hoursValue, minutesValue, secondsValue)
Returns the number of milliseconds since January 1, 1970 at 00:00:00 GMT. yearValue
is an integer greater than 1900. monthValue is an integer from 0 to 11. dateValue
is an integer from 1 to 31. hoursValue is an integer from 0 to 23. minutesValue and
secondsValue are integers from 0 to 59. hoursValue, minutesValue, and secondsValue
are optional. [Not I]
The document Object [C|2|3|I]
The document object reflects attributes of an HTML document in JavaScript.
Properties
Methods
- n clear() Clears the document window. [Not I]
- close() Closes the current output stream.
- open(mimeType) Opens a stream that allows write() and writeln()
methods to write to the document window. mimeType is an optional string that specifies
a document type supported by Navigator or a plug-in (for example, text/html,
image/gif, and so on).
-
write() Writes text and HTML to the specified document.
- writeln() Writes text and HTML to the specified document followed by a newline
character.
The FileUpload Object [C|3]
Reflects a file upload element in an HTML form.
Properties
The form Object [C|2|3|I]
The form object reflects an HTML form in JavaScript. Each HTML form in a
document is reflected by a distinct instance of the form object.
Properties
Methods
Event Handlers
The frame Object [C|2|3|I]
The frame object reflects a frame window in JavaScript.
Properties
Methods
- n alert(message) Displays message in a dialog box.
- blur() Removes focus from the frame. [Not 2]
- close() Closes the window.
- confirm(message) Displays message in a dialog box with OK and Cancel buttons.
Returns true or false based on the button clicked by the user.
- focus() Gives focus to the frame. [Not 2]
- open(url,name,features) Opens url in a window named name. If name doesn't exist,
a new window is created with that name. features is an optional string argument containing
a list of features for the new window. The feature list contains any of the following
name-value pairs separated by commas and without additional spaces:
toolbar=[yes,no,1,0] Indicates whether the window should have a toolbar
location=[yes,no,1,0] Indicates whether the window should have a location
field
directories=[yes,no,1,0] Indicates whether the window should have directory
buttons
status=[yes,no,1,0] Indicates whether the window should have a status
bar
menubar=[yes,no,1,0] Indicates whether the window should have menus
scrollbars=[yes,no,1,0] Indicates whether the window should have scrollbars
resizable=[yes,no,1,0] Indicates whether the window should be resizable
width=pixels Indicates the width of the window in pixels
- height=pixels Indicates the height of the window in pixels
- name = setTimeOut(expression,time)
- clearTimeout(name) Cancels the time-out with the name name.
Event Handlers
The Function Object [C|3]
The Function object provides a mechanism for indicating JavaScript code
to compile as a function. The syntax to use the Function object is functionName
= new Function(arg1, arg2, arg3, ..., functionCode).
This is similar to
function functionName(arg1, arg2, arg3, ...) {
functionCode
}
except that in the former, functionName is a variable with a reference to the function,
and the function is evaluated each time it is used rather than being compiled once.
Properties
The hidden Object [C|2|3|I]
The hidden object reflects a hidden field from an HTML form in JavaScript.
Properties
The history Object [C|2|3|I]
The history object allows a script to work with the Navigator browser's
history list in JavaScript. For security and privacy reasons, the actual content
of the list is not reflected into JavaScript.
Property
- n length An integer representing the number of items on the history
list. [Not I]
Methods
- back() Goes back to the previous document in the history list. [Not I]
- forward() Goes forward to the next document in the history list. [Not I]
- go(location) Goes to the document in the history list specified by location.
location can be a string or integer value. If it is a string, it represents all or
part of a URL in the history list. If it is an integer, location represents the relative
position of the document on the history list. As an integer, location can be positive
or negative. [Not I]
The Image Object [C|3]
The Image object reflects an image included in an HTML document.
Properties
Event Handlers
The link Object [C|2|3|I]
The link object reflects a hypertext link in the body of a document.
Properties
- n hash A string value containing the anchor name in the URL.
- host A string value containing the host name and port number from the URL.
- hostname A string value containing the domain name (or numerical IP address)
from the URL.
- href A string value containing the entire URL.
- pathname A string value specifying the path portion of the URL.
- port A string value containing the port number from the URL.
- protocol A string value containing the protocol from the URL (including the colon,
but not the slashes).
- search A string value containing any information passed to a GET CGI-BIN
call (that is, any information after the question mark).
- target A string value containing the name of the window or frame specified in
the TARGET attribute.
Event Handlers
The location Object [C|2|3|I]
The location object reflects information about the current URL.
Properties
- n hash A string value containing the anchor name in the URL.
- host A string value containing the host name and port number from the URL.
- hostname A string value containing the domain name (or numerical IP address)
from the URL.
- href A string value containing the entire URL.
- pathname A string value specifying the path portion of the URL.
- port A string value containing the port number from the URL.
- protocol A string value containing the protocol from the URL (including the colon,
but not the slashes).
- search A string value containing any information passed to a GET CGI-BIN
call (that is, any information after the question mark).
Methods
The Math Object [C|2|3|I]
The Math object provides properties and methods for advanced mathematical
calculations.
Properties
Methods
- n abs(number) Returns the absolute value of number. The absolute value
is the value of a number with its sign ignored, so abs(4) and abs(-4)
both return 4.
- acos(number) Returns the arccosine of number in radians.
- asin(number) Returns the arcsine of number in radians.
-
atan(number) Returns the arctangent of number in radians.
- atan2(number1,number2) Returns the angle of the polar coordinate corresponding
to the Cartesian coordinate (number1, number2). [Not I]
- ceil(number) Returns the next integer greater than number--in other words, rounds
up to the next integer.
- cos(number) Returns the cosine of number where number represents an angle in
radians.
- exp(number) Returns the value of e to the power of number.
- floor(number) Returns the next integer less than number--in other words, rounds
down to the nearest integer.
- log(number) Returns the natural logarithm of number.
- max(number1,number2) Returns the greater of number1 and number2.
- min(number1,number2) Returns the smaller of number1 and number2.
- pow(number1,number2) Returns the value of number1 to the power of number2.
- random() Returns a random number between zero and one.
- round(number) Returns the closest integer to number--in other words rounds to
the closest integer.
- sin(number) Returns the sine of number, where number represents an angle in radians.
- sqrt(number) Returns the square root of number.
- tan(number) Returns the tangent of number, where number represents an angle in
radians.
The mimeType Object [C|3]
The mimeType object reflects a MIME type supported by the client browser.
Properties
The navigator Object [C|2|3|I]
The navigator object reflects information about the version of Navigator
being used.
Properties
- versionNumber (platform; country)
- Mozilla/2.0b6 (Win32; I)
Method
- n javaEnabled() Returns a Boolean value indicating whether Java is enabled
in the browser. [Not 2|I]
The Option Object [C|3]
The Option object is used to create entries in a select list using the syntax
optionName = new Option(optionText, optionValue, defaultSelected,
selected) and then selectName.options[index] = optionName.
Properties
The password Object [C|2|3|I]
The password object reflects a password text field from an HTML form in
JavaScript.
Properties
Methods
Event Handlers
The plugin Object
The plugin object reflects a plug-in supported by the browser.
Properties
The radio Object [C|2|3|I]
The radio object reflects a set of radio buttons from an HTML form in JavaScript.
To access individual radio buttons, use numeric indexes starting at zero. For instance,
individual buttons in a set of radio buttons named testRadio could be referenced
by testRadio[0], testRadio[1], and so on.
Properties
- n checked A Boolean value indicating whether a specific button is checked.
Can be used to select or deselect a button.
- defaultChecked A Boolean value indicating whether a specific button was checked
by default (that is, reflects the CHECKED attribute). [Not I]
- enabled A Boolean value indicating whether the radio button is enabled. [Not
2|3]
- form A reference to the form object containing the radio button. [Not
2|3]
- length An integer value indicating the number of radio buttons in the set. [Not
I]
- name A string value containing the name of the set of radio buttons.
- value A string value containing the value of a specific radio button in a set
(that is, reflects the VALUE attribute).
Methods
Event Handlers
The reset Object [C|2|3|I]
The reset object reflects a reset button from an HTML form in JavaScript.
Properties
Methods
Event Handlers
The select Object [C|2|3]
The select object reflects a selection list from an HTML form in JavaScript.
Properties
defaultSelected A Boolean value indicating whether an option was selected
by default (that is, reflects the SELECTED attribute).
index An integer value reflecting the index of an option.
length An integer value reflecting the number of options in the selection
list.
name A string value containing the name of the selection list.
selected A Boolean value indicating whether the option is selected. Can
be used to select or deselect an option.
selectedIndex An integer value containing the index of the currently
selected option.
text A string value containing the text displayed in the selection list
for a particular option.
- value A string value indicating the value for the specified option (that
is, reflects the VALUE attribute).
- selectedIndex Reflects the index of the currently selected option in the selection
list.
Methods
Event Handlers
The String Object [C|2|3|I]
The String object provides properties and methods for working with string
literals and variables.
Properties
Methods
- n anchor(name) Returns a string containing the value of the String
object surrounded by an A container tag with the NAME attribute
set to name.
- big() Returns a string containing the value of the String object surrounded
by a BIG container tag.
- blink() Returns a string containing the value of the String object surrounded
by a BLINK container tag.
- bold() Returns a string containing the value of the String object surrounded
by a B container tag.
- charAt(index) Returns the character at the location specified by index.
- fixed() Returns a string containing the value of the String object surrounded
by a FIXED container tag.
- fontColor(color) Returns a string containing the value of the String
object surrounded by a FONT container tag with the COLOR attribute
set to color, where color is a color name or an RGB triplet. [Not I]
- fontSize(size) Returns a string containing the value of the String object
surrounded by a FONTSIZE container tag with the size set to size. [Not I]
- indexOf(findString,startingIndex) Returns the index of the first occurrence of
findString, starting the search at startingIndex, where startingIndex is optional--if
it is not provided, the search starts at the start of the string.
- italics() Returns a string containing the value of the String object
surrounded by an I container tag.
- lastIndexOf(findString,startingIndex) Returns the index of the last occurrence
of findString. This is done by searching backward from startingIndex. startingIndex
is optional and assumed to be the last character in the string if no value is provided.
- link(href) Returns a string containing the value of the String object
surrounded by an A container tag with the HREF attribute set to
href.
- small() Returns a string containing the value of the String object surrounded
by a SMALL container tag.
- split(separator) Returns an array of strings created by splitting the string
at every occurrence of separator. [Not 2|I]
- strike() Returns a string containing the value of the String object
surrounded by a STRIKE container tag.
- sub() Returns a string containing the value of the String object surrounded
by a SUB container tag.
- substring(firstIndex,lastIndex) Returns a string equivalent to the substring
starting at firstIndex and ending at the character before lastIndex. If firstIndex
is greater than lastIndex, the string starts at lastIndex and ends at the character
before firstIndex.
- sup() Returns a string containing the value of the String object surrounded
by a SUP container tag.
- toLowerCase() Returns a string containing the value of the String object
with all characters converted to lowercase.
- toUpperCase() Returns a string containing the value of the String object
with all characters converted to uppercase.
The submit Object [C|2|3|I]
The submit object reflects a submit button from an HTML form in JavaScript.
Properties
Methods
Event Handlers
The text Object [C|2|3|I]
The text object reflects a text field from an HTML form in JavaScript.
Properties
Methods
Event Handlers
The textarea Object [C|2|3|I]
The textarea object reflects a multiline text field from an HTML form in
JavaScript.
Properties
Methods
Event Handlers
The window Object [C|2|3|I]
The window object is the top-level object for each window or frame and is
the parent object for the document, location, and history objects.
Properties
Methods
- n alert(message) Displays message in a dialog box.
- blur() Removes focus from the window. On many systems, this sends the window
to the background. [Not 2|I]
- close() Closes the window. [Not I]
- confirm(message) Displays message in a dialog box with OK and Cancel buttons.
Returns true or false based on the button clicked by the user.
- focus() Gives focus to the window. On many systems, this brings the window to
the front. [Not 2|I]
- navigator(url) Loads url in the window. [Not 2|3]
- open(url,name,features) Opens url in a window named name. If name doesn't exist,
a new window is created with that name. features is an optional string argument containing
a list of features for the new window. The feature list contains any of the following
name-value pairs separated by commas and without additional spaces [Not I]:
toolbar=[yes,no,1,0] Indicates whether the window should have a toolbar
location=[yes,no,1,0] Indicates whether the window should have a location
field
directories=[yes,no,1,0] Indicates whether the window should have directory
buttons
status=[yes,no,1,0] Indicates whether the window should have a status
bar
menubar=[yes,no,1,0] Indicates whether the window should have menus
scrollbars=[yes,no,1,0] Indicates whether the window should have scrollbars
resizable=[yes,no,1,0] Indicates whether the window should be resizable
width=pixels Indicates the width of the window in pixels
- height=pixels Indicates the height of the window in pixels
- name = setTimeOut(expression,time)
Event Handlers
Independent Functions, Operators,
Variables, and Literals
Independent Functions
- n escape(character) Returns a string containing the ASCII encoding of
character in the form %xx, where xx is the numeric encoding of
the character. [C|2|3|I]
- eval(expression) Returns the result of evaluating expression, where expression
is an arithmetic expression. [C|2|3|I]
- isNaN(value) Evaluates value to see whether it is NaN. Returns a Boolean
value. [C|2|3|I] [On UNIX platforms, Not 2]
- parseFloat(string) Converts string to a floating-point number and returns the
value. It continues to convert until it hits a non-numeric character and then returns
the result. If the first character cannot be converted to a number, the function
returns "NaN" (0 on Windows platforms). [C|2|3|I]
- parseInt(string,base) Converts string to an integer of base base and returns
the value. It continues to convert until it hits a non-numeric character and then
returns the result. If the first character cannot be converted to a number, the function
returns "NaN" (0 on Windows platforms). [C|2|3|I]
- taint(propertyName) Adds tainting to propertyName. [C|3]
- toString() This is a method of all objects. It returns the object as a string
or returns "[object type]" if no string representation
exists for the object. [C|2|3]
- unescape(string) Returns a character based on the ASCII encoding contained in
string. The ASCII encoding should take the form "%integer" or
"hexadecimalValue". [C|2|3|I]
- untaint(propertyName) Removes tainting from propertyName. [C|3]
Operators
- n Assignment operators Table E.1 shows the assignment operators in JavaScript.
[C|2|3|I]
Table E.1. Assignment operators.
Operator |
Description |
= |
Assigns the value of the right operand to the left operand |
+= |
Adds the left and right operands and assigns the result to the left operand |
-= |
Subtracts the right operand from the left operand and assigns the result to the left
operand |
*= |
Multiplies the two operands and assigns the result to the left operand |
/= |
Divides the left operand by the right operand and assigns the value to the left operand |
%= |
Divides the left operand by the right operand and assigns the remainder to the left
operand |
- Arithmetic operators Table E.2 shows the arithmetic operators in JavaScript.
[C|2|3|I]
Table E.2. Arithmetic operators.
Operator |
Description |
+ |
Adds the left and right operands |
- |
Subtracts the right operand from the left operand |
* |
Multiplies the two operands |
/ |
Divides the left operand by the right operand |
% |
Divides the left operand by the right operand and evaluates to the remainder |
++ |
Increments the operand by one (can be used before or after the operand) |
-- |
Decreases the operand by one (can be used before or after the operand) |
- |
Changes the sign of the operand |
- Bitwise operators Bitwise operators deal with their operands as binary numbers
but return JavaScript numerical value (see Table E.3). [C|2|3|I]
Table E.3. Bitwise operators in JavaScript.
Operator |
Description |
AND (or &) |
Converts operands to integers with 32 bits, pairs the corresponding bits, and returns
one for each pair of ones. Returns zero for any other combination. |
OR (or |) |
Converts operands to integers with 32 bits, pairs the corresponding bits, and returns
one for each pair where one of the two bits is one. Returns zero if both bits are
zero. |
XOR (or ^) |
Converts operands to integers with 32 bits, pairs the corresponding bits, and returns
one for each pair where only one bit is one. Returns zero for any other combination. |
<< |
Converts the left operand to an integer with 32 bits and shifts bits to the left
the number of bits indicated by the right operand--bits shifted off to the left are
discarded and zeros are shifted in from the right. |
>> |
Converts the left operand to an integer with 32 bits and shifts bits to the right
the number of bits indicated by the right operand--bits shifted off to the right
are discarded and copies of the left-most bit are shifted in from the left. |
- Logical operators Table E.4 shows the logical operators in JavaScript. [C|2|3|I]
Table E.4. Logical operators.
Operator |
Description |
&& |
Logical AND--returns true when both operands are true; otherwise
it returns false. |
|| |
Logical OR--returns true if either operand is true. It only returns
false when both operands are false. |
! |
Logical NOT--returns true if the operand is false and false
if the operand is true. This is a unary operator |
and it precedes the operand. |
|
- Comparison operators Table E.5 shows the comparison operators in JavaScript.
[C|2|3|I]
Table E.5. Logical (comparison) operators.
Operator |
Description |
== |
Returns true if the operands are equal |
!= |
Returns true if the operands are not equal |
> |
Returns true if the left operand is greater than the |
right operand |
|
< |
Returns true if the left operand is less than the right operand |
>= |
Returns true if the left operand is greater than or |
equal to the right operand |
|
<= |
Returns true if the left operand is less than or equal |
to the right operand |
|
- Conditional operators Conditional expressions take one form:
- (condition) ? val1 : val2
- If condition is true, the expression evaluates to val1; otherwise, it evaluates
to val2. [C|2|3|I]
- String operators The concatenation operators (+) is one of two string operators.
It evaluates to a string combining the left and right operands. The concatenation
assignment operator (+=) is also available. [C|2|3|I]
- The typeof operator The typeof operator returns the type of
its single operand. Possible types are object, string, number,
boolean, function, and undefined. [C|3|I]
- The void operator The void operator takes an expression as
an operand but returns no value. [C|3]
- Operator precedence JavaScript applies the rules of operator precedence
as follows (from lowest to highest precedence):
comma (,)
assignment operators (= += -= *= /=
%=)
conditional (? :)
logical OR (||)
logical AND (&&)
bitwise OR (|)
bitwise XOR (^)
bitwise AND (&)
equality (== !=)
relational (< <= > >=)
shift (<< >> >>>)
addition/subtraction (+ -)
multiply/divide/modulus (* / %)
negation/increment (! - ++ --)
- call, member (() [])
|