This part of the book is a reference section that documents the classes, methods, and properties defined by the core JavaScript language. The introduction and sample reference page explain how to use and get the most out of this reference section. Take the time to read this material carefully, and you will find it easier to locate and use the information you need!
This reference section is arranged alphabetically. The reference pages for the methods and properties of classes are alphabetized by their full names, which include the names of the classes that define them. For example, if you want to read about the replace( ) method of the String class, you would look under "String.replace," not just "replace."
Core JavaScript defines some global functions and properties, such as eval( ) and NaN. Technically, these are properties of a global object. Since the global object has no name, however, they are listed in this reference section under their own unqualified names. For convenience, the full set of global functions and properties in core JavaScript is summarized in a special reference page named "Global" (even though there is no object or class by that name).
Sometimes you may find that you don't know the name of the class or interface that defines the method or property want to look up, or you may not be sure which of the three reference sections to look up a class or interface in. Part VI of this book is a special index designed to help with these situations. Look up the name of a class, method, or property, and it will tell you which reference section to look in and which class to look under in that section. For example, if you look up "Date," it will tell you that the Date class is documented in this core reference section. And if you look up the name "match," it will tell you that match( ) is a method of the String class and is also documented in this section.
Once you've found the reference page you're looking for, you shouldn't have much difficulty finding the information you need. Still, you'll be able to make better use of this reference section if you understand how the reference pages are written and organized. What follows is a sample reference page titled "Sample Entry" that demonstrates the structure of each reference page and tells you where to find various types of information within the pages. Take the time to read this page before diving into the rest of the reference material.
| Sample Entry | how to read core JavaScript reference pages |
Every reference entry begins with a title block like that above. The entries are alphabetized by title. The short description, shown next to the title, gives you a quick summary of the item documented in the entry; it can help you quickly decide if you're interested in reading the rest of the page.
This information tells you which version of Netscape's JavaScript interpreter and Microsoft's JScript interpreter the item (class, method, or property) was introduced in. If the item has been standardized in ECMAScript, it tells you which version of the standard introduced it. You can assume that anything available in one version of JavaScript is also available in later versions. Note, however, that if this section says the item is deprecated it may be removed in the future and you should avoid using it.
If a class inherits from a superclass or a method overrides a method in a superclass, that information is shown in the "Inherits from/Overrides" section.
As described in Chapter 8, JavaScript classes can inherit properties and methods from other classes. For example, the String class inherits from Object, and the RangeError class inherits from Error, which in turn inherits from Object. When you see this inheritance information, you may also want to look up the listed superclasses.
When a method has the same name as a method in a superclass, the method overrides the superclass's method. See Array.toString( ) for an example.
If the reference page documents a class, it usually has a "Constructor" section that shows you how to use the constructor method to create instances of the class. Since constructors are a type of method, the "Constructor" section looks a lot like the "Synopsis" section of a method's reference page.
Reference pages for functions, methods, and properties have a "Synopsis" section that shows how you might use the function, method, or property in your code. For example, the synopsis for the Array.concat( ) method is:
array.concat(value, ...)
The italic font indicates text that is to be replaced with something else. array should be replaced with a variable or JavaScript expression that holds or evaluates to an array. And value simply represents an arbitrary value that is to be concatenated to the array. The ellipsis (...) indicates that this method can take any number of value arguments. Because the terms concat and the open and close parentheses are not in italics, you must include them exactly as shown in your JavaScript code.
If a reference page documents a function, a method, or a class with a constructor method, the "Constructor" or "Synopsis" section is followed by an "Arguments" subsection that describes the arguments to the method, function, or constructor. If there are no arguments, this subsection is simply omitted.
If a constructor, function, or method has a return value, this subsection explains that value.
If a constructor, function, or method can throw an exception, this subsection lists the types of exceptions that may be thrown and explains the circumstances under which this can occur.
If the reference page documents a class, the "Properties" section lists the properties defined by the class and provides short explanations of each. In this core reference section, each property also has a complete reference page of its own. For example, the reference page for the Array class lists the length property in this section and gives a brief explanation of it, but the property is fully documented in the "Array.length" reference page. The property listing looks like this:
The reference page for a class that defines methods includes a "Methods" section. It is just like the "Properties" section, except that it summarizes methods instead of properties. All methods also have reference pages of their own.
Most reference pages contain a "Description" section, which is the basic description of the class, method, function, or property that is being documented. This is the heart of the reference page. If you are learning about a class, method, or property for the first time, you may want to skip directly to this section and then go back and look at previous sections such as "Arguments," "Properties," and "Methods." If you are already familiar with a class, method, or property, you probably won't need to read this section and instead will just want to quickly look up some specific bit of information (for example, from the "Arguments" or "Properties" sections).
In some entries, this section is no more than a short paragraph. In others, it may occupy a page or more. For some simple methods, the "Arguments" and "Returns" sections document the method sufficiently by themselves, so the "Description" section is omitted.
Some pages include an example that shows typical usage. Most pages do not contain examples, however -- you'll find those in first half of this book.
When an item doesn't work quite right, this section describes the bugs. Note, however, that this book does not attempt to catalog every bug in every version and implementation of JavaScript.
Many reference pages conclude with cross-references to related reference pages that may be of interest. Sometimes reference pages also refer back to one of the main chapters of the book.
| arguments[ ] | an array of function arguments |
JavaScript 1.1; JScript 2.0; ECMAScript v1
arguments
The arguments[] array is defined only within a function body. Within the body of a function, arguments refers to the Arguments object for the function. This object has numbered properties and serves as an array containing all arguments passed to the function. The arguments identifier is essentially a local variable automatically declared and initialized within every function. It refers to an Arguments object only within the body of a function and is undefined in global code.
| Arguments | arguments and other properties of a function |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Inherits from Object
arguments arguments[n]
The Arguments object is defined only within a function body. Although it is not technically an array, the Arguments object has numbered properties that function as array elements and a length property that specifies the number of array elements. Its elements are the values that were passed as arguments to the function. Element 0 is the first argument, element 1 is the second argument, and so on. All values passed as arguments become array elements of the Arguments object, whether or not those arguments are given names in the function declaration.
When a function is invoked, an Arguments object is created for it and the local variable arguments is automatically initialized to refer to that Arguments object. The main purpose of the Arguments object is to provide a way to determine how many arguments were passed to the function and to refer to unnamed arguments. In addition to the array elements and length property, however, the callee property allows an unnamed function to refer to itself.
For most purposes, the Arguments object can be thought of as an array with the addition of the callee property. However, it is not an instance of Array, and the Arguments.length property does not have any of the special behaviors of the Array.length property and cannot be used to change the size of the array.
The Arguments object has one very unusual feature. When a function has named arguments, the array elements of the Arguments object are synonyms for the local variables that hold the function arguments. The Arguments object and the argument names provide two different ways of referring to the same variable. Changing the value of an argument with an argument name changes the value that is retrieved through the Arguments object, and changing the value of an argument through the Arguments object changes the value that is retrieved by the argument name.
| Arguments.callee | the function that is currently running |
JavaScript 1.2; JScript 5.5; ECMAScript v1
arguments.callee
arguments.callee refers to the function that is currently running. It provides a way for an unnamed function to refer to itself. This property is defined only within a function body.
// An unnamed function literal uses the callee property to refer
// to itself so that it can be recursive
var factorial = function(x) {
if (x < 2) return 1;
else return x * arguments.callee(x-1);
}
var y = factorial(5); // Returns 120
| Arguments.length | the number of arguments passed to a function |
JavaScript 1.1; JScript 2; ECMAScript v1
arguments.length
The length property of the Arguments object specifies the number of arguments passed to the current function. This property is defined only within a function body.
Note that this property specifies the number of arguments actually passed, not the number expected. See Function.length for the number of declared arguments. Note also that this property does not have any of the special behavior of the Array.length property.
// Use an Arguments object to check that correct # of args were passed
function check(args) {
var actual = args.length; // The actual number of arguments
var expected = args.callee.length; // The expected number of arguments
if (actual != expected) { // Throw exception if they don't match
throw new Error("Wrong number of arguments: expected: " +
expected + "; actually passed " + actual);
}
}
// A function that demonstrates how to use the function above
function f(x, y, z) {
check(arguments); // Check for correct number of arguments
return x + y + z; // Now do the rest of the function normally
}
| Array | built-in support for arrays |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Inherits from Object
new Array( ) new Array(size) new Array(element0, element1, ..., elementn)
The newly created and initialized array. When Array( ) is invoked with no arguments, the returned array is empty and has a length field of 0. When invoked with a single numeric argument, the constructor returns an array with the specified number of undefined elements. When invoked with any other arguments, the constructor initializes the array with the values specified by the arguments. When the Array( ) constructor is called as a function, without the new operator, it behaves exactly as it does when called with the new operator.
ECMAScript v3 specifies and JavaScript 1.2 and JScript 3.0 implement an array literal syntax. You may also create and initialize an array by placing a comma-separated list of expressions within square brackets. The values of these expressions become the elements of the array. For example:
var a = [1, true, 'abc']; var b = [a[0], a[0]*2, f(x)];
Arrays are a basic feature of JavaScript and are documented in detail in Chapter 9.
| Array.concat( ) | concatenate arrays |
JavaScript 1.2; JScript 3.0; ECMAScript v3
array.concat(value, ...)
A new array, which is formed by concatenating each of the specified arguments to array.
concat( ) creates and returns a new array that is the result of concatenating each of its arguments to array. It does not modify array. If any of the arguments to concat( ) is itself an array, the elements of that array are concatenated, rather than the array itself.
var a = [1,2,3]; a.concat(4, 5) // Returns [1,2,3,4,5] a.concat([4,5]); // Returns [1,2,3,4,5] a.concat([4,5],[6,7]) // Returns [1,2,3,4,5,6,7] a.concat(4, [5,[6,7]]) // Returns [1,2,3,4,5,[6,7]]
| Array.join( ) | concatenate array elements to form a string |
JavaScript 1.1; JScript 2.0; ECMAScript v1
array.join( ) array.join(separator)
The string that results from converting each element of array to a string and then concatenating them together, with the separator string between elements.
join( ) converts each of the elements of an array to a string and then concatenates those strings, inserting the specified separator string between the elements. It returns the resulting string.
You can perform a conversion in the opposite direction -- splitting a string up into array elements -- with the split( ) method of the String object. See the String.split( ) reference page for details.
a = new Array(1, 2, 3, "testing");
s = a.join("+"); // s is the string "1+2+3+testing"
| Array.length | the size of an array |
JavaScript 1.1, JScript 2.0; ECMAScript v1
array.length
The length property of an array is always one larger than the highest element defined in the array. For traditional "dense" arrays that have contiguous elements and begin with element 0, the length property specifies the number of elements in the array.
The length property of an array is initialized when the array is created with the Array( ) constructor method. Adding new elements to an array updates the length, if necessary:
a = new Array( ); // a.length initialized to 0
b = new Array(10); // b.length initialized to 10
c = new Array("one", "two", "three"); // c.length initialized to 3
c[3] = "four"; // c.length updated to 4
c[10] = "blastoff"; // c.length becomes 11
You can set the value of the length property to change the size of an array. If you set length to be smaller than its previous value, the array is truncated and elements at the end are lost. If you set length to be larger than its previous value, the array becomes bigger and the new elements added at the end of the array have the undefined value.
| Array.pop( ) | remove and return the last element of an array |
JavaScript 1.2; JScript 5.5; ECMAScript v3
array.pop( )
The last element of array.
pop( ) deletes the last element of array, decrements the array length, and returns the value of the element that it deleted. If the array is already empty, pop( ) does not change the array and returns the undefined value.
pop( ), and its companion method push( ), provide the functionality of a first-in, last-out stack. For example:
var stack = []; // stack: [] stack.push(1, 2); // stack: [1,2] Returns 2 stack.pop( ); // stack: [1] Returns 2 stack.push([4,5]); // stack: [1,[4,5]] Returns 2 stack.pop( ) // stack: [1] Returns [4,5] stack.pop( ); // stack: [] Returns 1
| Array.push( ) | append elements to an array |
JavaScript 1.2; JScript 5.5; ECMAScript v3
array.push(value, ...)
The new length of the array, after the specified values are appended to it.
push( ) appends its arguments, in order, to the end of array. It modifies array directly, rather than creating a new array. push( ), and its companion method pop( ), use arrays to provide the functionality of a first in, last out stack. See Array.pop( ) for an example.
In Netscape's implementations of JavaScript, when the language version is explicitly set to 1.2 this function returns the last value appended, rather than returning the new array length.
| Array.reverse( ) | reverse the elements of an array |
JavaScript 1.1; JScript 2.0; ECMAScript v1
array.reverse( )
The reverse( ) method of an Array object reverses the order of the elements of an array. It does this "in place" -- it rearranges the elements of the specified array, without creating a new array. If there are multiple references to array, the new order of the array elements is visible through all references.
a = new Array(1, 2, 3); // a[0] == 1, a[2] == 3; a.reverse( ); // Now a[0] == 3, a[2] == 1;
| Array.shift( ) | shift array elements down |
JavaScript 1.2; JScript 5.5; ECMAScript v3
array.shift( )
The former first element of the array.
shift( ) removes and returns the first element of array, shifting all subsequent elements down one place to occupy the newly vacant space at the start of the array. If the array is empty, shift( ) does nothing and returns the undefined value. Note that shift( ) does not create a new array; instead, it modifies array directly.
shift( ) is similar to Array.pop( ), except it operates on the beginning of an array rather than the end. shift( ) is often used in conjunction with unshift( ).
var a = [1, [2,3], 4] a.shift( ); // Returns 1; a = [[2,3], 4] a.shift( ); // Returns [2,3]; a = [4]
| Array.slice( ) | return a portion of an array |
JavaScript 1.2; JScript 3.0; ECMAScript v3
array.slice(start, end)
A new array that contains the elements of array from the element specified by start, up to, but not including, the element specified by end.
slice( ) returns a slice, or subarray, of array. The returned array contains the element specified by start and all subsequent elements up to, but not including, the element specified by end. If end is not specified, the returned array contains all elements from the start to the end of array.
Note that slice( ) does not modify the array. If you want to actually remove a slice of an array, use Array.splice( ).
var a = [1,2,3,4,5]; a.slice(0,3); // Returns [1,2,3] a.slice(3); // Returns [4,5] a.slice(1,-1); // Returns [2,3,4] a.slice(-3,-2); // Returns [3]; buggy in IE 4: returns [1,2,3]
start cannot be a negative number in Internet Explorer 4.
| Array.sort( ) | sort the elements of an array |
JavaScript 1.1; JScript 2.0; ECMAScript v1
array.sort( ) array.sort(orderfunc)
A reference to the array. Note that the array is sorted in place and no copy is made.
The sort( ) method sorts the elements of array in place -- no copy of the array is made. If sort( ) is called with no arguments, the elements of the array are arranged in alphabetical order (more precisely, the order determined by the character encoding). To do this, elements are first converted to strings, if necessary, so that they can be compared.
If you want to sort the array elements in some other order, you must supply a comparison function that compares two values and returns a number indicating their relative order. The comparison function should take two arguments, a and b, and should return one of the following:
A value less than zero, if, according to your sort criteria, a is "less than" b and should appear before b in the sorted array.
Zero, if a and b are equivalent for the purposes of this sort.
A value greater than zero, if a is "greater than" b for the purposes of the sort.
Note that undefined elements of an array are always sorted to the end of the array. This is true even if you provide a custom ordering function: undefined values are never passed to the orderfunc you supply.
The following code shows how you might write a comparison function to sort an array of numbers in numerical, rather than alphabetical order:
// An ordering function for a numerical sort
function numberorder(a, b) { return a - b; }
a = new Array(33, 4, 1111, 222);
a.sort( ); // Alphabetical sort: 1111, 222, 33, 4
a.sort(numberorder); // Numerical sort: 4, 33, 222, 1111
| Array.splice( ) | insert, remove, or replace array elements |
JavaScript 1.2; JScript 5.5; ECMAScript v3
array.splice(start, deleteCount, value, ...)
An array containing the elements, if any, deleted from array. Note, however, that due to a bug, the return value is not always an array in the Netscape implementation of JavaScript 1.2.
splice( ) deletes zero or more array elements starting with and including the element start and replaces them with zero or more values specified in the argument list. Array elements that appear after the insertion or deletion are moved as necessary so that they remain contiguous with the rest of the array. Note that, unlike the similarly named slice( ), splice( ) modifies array directly.
The operation of splice( ) is most easily understood through an example:
var a = [1,2,3,4,5,6,7,8] a.splice(4); // Returns [5,6,7,8]; a is [1,2,3,4] a.splice(1,2); // Returns [2,3]; a is [1,4] a.splice(1,1); // Netscape/JavaScript 1.2 returns 4 instead of [4] a.splice(1,0,2,3); // Netscape/JavaScript 1.2 returns undefined instead of []
splice( ) is supposed to return an array of deleted elements in all cases. However, in Netscape's JavaScript 1.2 interpreter, when a single element is deleted it returns that element rather than an array containing the element. Also, if no elements are deleted, it returns nothing instead of returning an empty array. Netscape implementions of JavaScript emulate this buggy behavior whenever Version 1.2 of the language is explicitly specified.
| Array.toLocaleString( ) | convert an array to a localized string |
JavaScript 1.5; JScript 5.5; ECMAScript v1
Overrides Object.toLocaleString( )
array.toLocaleString( )
A localized string representation of array.
The toString( ) method of an array returns a localized string representation of an array. It does this by calling the toLocaleString( ) method of all of the array elements, then concatenating the resulting strings using a locale-specific separator character.
| Array.toString( ) | convert an array to a string |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Overrides Object.toString( )
array.toString( )
A string representation of array.
The toString( ) method of an array converts an array to a string and returns the string. When an array is used in a string context, JavaScript automatically converts it to a string by calling this method. On some occasions, however, you may want to call toString( ) explicitly.
toString( ) converts an array to a string by first converting each of the array elements to strings (by calling their toString( ) methods). Once each element is converted to a string, it outputs them in a comma-separated list. This return value is the same string that would be returned by the join( ) method with no arguments.
In Netscape implementations, when Version 1.2 of the language is explicitly specified, toString( ) returns its list of comma-and-space-separated array elements within square brackets using array literal notation. This occurs, for example, when the language attribute of a <script> tag is explicitly specified as "JavaScript1.2".
| Array.unshift( ) | insert elements at the beginning of an array |
JavaScript 1.2; JScript 5.5; ECMAScript v3
array.unshift(value, ...)
The new length of the array.
unshift( ) inserts its arguments at the beginning of array, shifting the existing elements to higher indexes to make room. The first argument to shift( ) becomes the new element 0 of the array, the second argument, if any, becomes the new element 1, and so on. Note that unshift( ) does not create a new array; it modifies array directly.
unshift( ) is often used in conjunction with shift( ). For example:
var a = []; // a:[] a.unshift(1); // a:[1] Returns: 1 a.unshift(22); // a:[22,1] Returns: 2 a.shift( ); // a:[1] Returns: 22 a.unshift(33,[4,5]); // a:[33,[4,5],1] Returns: 3
| Boolean | support for boolean values |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Inherits from Object
new Boolean(value) //Constructor function Boolean(value) // Conversion function
When invoked as a constructor with the new operator, Boolean( ) converts its argument to a boolean value and returns a Boolean object that contains that value. When invoked as a function, without the new operator, Boolean( ) simply converts its argument to a primitive boolean value and returns that value.
The values 0, NaN, null, the empty string "", and the undefined value are all converted to false. All other primitive values, except false (but including the string "false"), and all objects and arrays are converted to true.
Boolean values are a fundamental data type in JavaScript. The Boolean object is an object wrapper around the boolean value. This Boolean object type exists primarily to provide a toString( ) method to convert boolean values to strings. When the toString( ) method is invoked to convert a boolean value to a string (and it is often invoked implicitly by JavaScript) JavaScript internally converts the boolean value to a transient Boolean object, on which the method can be invoked.
| Boolean.toString( ) | convert a boolean value to a string |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Overrides Object.toString( )
b.toString( )
The string "true" or "false", depending on the value of the primitive boolean value or Boolean object b.
| Boolean.valueOf( ) | the boolean value of a Boolean object |
JavaScript 1.1; JScript 2.0; ECMAScript v1
Overrides Object.valueOf( )
b.valueOf( )
The primitive boolean value held by the Boolean object b.
| Date | manipulate dates and times |
JavaScript 1.0; JScript 1.0; ECMAScript v1
Inherits from Object
new Date( ) new Date(milliseconds) new Date(datestring) new Date(year, month, day, hours, minutes, seconds, ms)
With no arguments, the Date( ) constructor creates a Date object set to the current date and time. When one numeric argument is passed, it is taken as the internal numeric representation of the date in milliseconds, as returned by the getTime( ) method. When one string argument is passed, it is a string representation of a date, in the format accepted by the Date.parse( ) method. Otherwise, the constructor is passed between two and seven numeric arguments that specify the individual fields of the date and time. All but the first two arguments -- the year and month fields -- are optional. Note that these date and time fields are specified using local time, not UTC (similar to GMT) time. See the static Date.UTC( ) method for an alternative.
Date( ) may also be called as a function, without the new operator. When invoked in this way, Date( ) ignores any arguments passed to it and returns a string representation of the current date and time.
The Date object has no properties that can be read and written directly; instead, all access to date and time values is done through methods. Most methods of the Date object come in two forms: one that operates using local time, and one that operates using universal (UTC or GMT) time. If a method has "UTC" in its name, it operates using universal time. These pairs of methods are listed together below. For example, the listing for get[UTC]Day( ) refers to both the methods getDay( ) and getUTCDay( ).
Date methods may be invoked only on Date objects and throw a TypeError exception if you attempt to invoke them on any other type of object.
In addition to the many instance methods listed above, the Date object also defines two static methods. These methods are invoked through the Date( ) constructor itself, not through individual Date objects:
The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) syntax shown in the preceding Constructor section.
Once a Date object is created, there are a number of methods that allow you to operate on it. Most of the methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time. The toString( ) method and its variants convert dates to human-readable strings. getTime( ) and setTime( ) convert to and from the internal representation of the Date object -- the number of milliseconds since midnight (GMT) on January 1, 1970. In this standard millisecond format, a date and time are represented by a single integer, which makes date arithmetic particularly easy. The ECMAScript standard requires the Date object to be able to represent any date and time, to millisecond precision, within 100 million days before or after 1/1/1970. This is a range of plus or minus 273,785 years, so the JavaScript clock will not "roll over" until the year 275755.
Once you create a Date object, there are a variety of methods you can use to operate on it:
d = new Date( ); // Get the current date and time
document.write('Today is: " + d.toLocaleDateString( ) + '. '); // Display date
document.write('The time is: ' + d.toLocaleTimeString( )); // Display time
var dayOfWeek = d.getDay( ); // What weekday is it?
var weekend = (dayOfWeek == 0) || (dayOfWeek == 6); // Is it a weekend?
Another common use of the Date object is to subtract the millisecond representations of the current time from some other time to determine the difference between the two times. The following client-side example shows two such uses:
<script language="JavaScript">
today = new Date( ); // Make a note of today's date
christmas = new Date( ); // Get a date with the current year
christmas.setMonth(11); // Set the month to December...
christmas.setDate(25); // and the day to the 25th
// If Christmas hasn't already passed, compute the number of
// milliseconds between now and Christmas, convert this
// to a number of days and print a message
if (today.getTime( ) < christmas.getTime( )) {
difference = christmas.getTime( ) - today.getTime( );
difference = Math.floor(difference / (1000 * 60 * 60 * 24));
document.write('Only ' + difference + ' days until Christmas!<p>');
}
</script>
// ... rest of HTML document here ...
<script language="JavaScript">
// Here we use Date objects for timing
// We divide by 1000 to convert milliseconds to seconds
now = new Date( );
document.write('<p>It took ' +
(now.getTime( )-today.getTime( ))/1000 +
'seconds to load this page.');
</script>
| Date.getDate( ) | return the day of the month |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getDate( )
The day of the month of the specified Date object date, using local time. Return values are between 1 and 31.
| Date.getDay( ) | return the day of the week |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getDay( )
The day of the week of the specified Date object date, using local time. Return values are between 0 (Sunday) and 6 (Saturday).
| Date.getFullYear( ) | return the year |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getFullYear( )
The year that results when date is expressed in local time. The return value is a full four-digit year, including the century, not a two-digit abbreviation.
| Date.getHours( ) | return the hours field of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getHours( )
The hours field, expressed in local time, of the specified Date object date. Return values are between 0 (midnight) and 23 (11 p.m.).
| Date.getMilliseconds( ) | return the milliseconds field of a Date |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getMilliseconds( )
The milliseconds field, expressed in local time, of date.
| Date.getMinutes( ) | return the minutes field of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getMinutes( )
The minutes field, expressed in local time, of the specified Date object date. Return values are between 0 and 59.
| Date.getMonth( ) | return the month of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getMonth( )
The month field, expressed in local time, of the specified Date object date. Return values are between 0 ( January) and 11 (December).
| Date.getSeconds( ) | return the seconds field of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getSeconds( )
The seconds field, expressed in local time, of the specified Date object date. Return values are between 0 and 59.
| Date.getTime( ) | return a Date in milliseconds |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getTime( )
The millisecond representation of the specified Date object date; that is, the number of milliseconds between midnight (GMT) on 1/1/1970 and the date and time specified by date.
getTime( ) converts a date and time to a single integer. This is useful when you want to compare two Date objects or to determine the time elapsed between two dates. Note that the millisecond representation of a date is independent of the time zone, so there is no getUTCTime( ) method in addition to this one. Don't confuse this getTime( ) method with the getDay( ) and getDate( ) methods, which return the day of the week and the day of the month, respectively.
Date.parse( ) and Date.UTC( ) allow you to convert a date and time specification to millisecond representation without going through the overhead of first creating a Date object.
| Date.getTimezoneOffset( ) | determine the offset from GMT |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.getTimezoneOffset( )
The difference, in minutes, between Greenwich Mean Time (GMT) and local time.
getTimezoneOffset( ) returns the number of minutes difference between the GMT or UTC time and the local time. In effect, this function tells you what time zone the JavaScript code is running in and whether or not daylight savings time is (or would be) in effect at the specified date.
The return value is measured in minutes, rather than hours, because some countries have time zones that are not at even one-hour intervals.
| Date.getUTCDate( ) | return the day of the month (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCDate( )
The day of the month (a value between 1 and 31) that results when date is expressed in universal time.
| Date.getUTCDay( ) | return the day of the week (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCDay( )
The day of the week that results when date is expressed in universal time. Return values are between 0 (Sunday) and 6 (Saturday).
| Date.getUTCFullYear( ) | return the year (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCFullYear( )
The year that results when date is expressed in universal time. The return value is a full four-digit year, not a two-digit abbreviation.
| Date.getUTCHours( ) | return the hours field of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCHours( )
The hours field, expressed in universal time, of date. The return value is an integer between 0 (midnight) and 23 (11 p.m.).
| Date.getUTCMilliseconds( ) | return the milliseconds field of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCMilliseconds( )
The milliseconds field, expressed in universal time, of date.
| Date.getUTCMinutes( ) | return the minutes field of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCMinutes( )
The minutes field, expressed in universal time, of date. The return value is an integer between 0 and 59.
| Date.getUTCMonth( ) | return the month of the year (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCMonth( )
The month of the year that results when date is expressed in universal time. The return value is an integer between 0 ( January) and 11 (December). Note that the Date object represents the first day of the month as 1 but represents the first month of the year as 0.
| Date.getUTCSeconds( ) | return the seconds field of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.getUTCSeconds( )
The seconds field, expressed in universal time, of date. The return value is an integer between 0 and 59.
| Date.getYear( ) | return the year field of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1; deprecated by ECMAScript v3
date.getYear( )
The year field of the specified Date object date minus 1900.
getYear( ) returns the year field of a specified Date object minus 1900. As of ECMAScript v3, it is not required in conforming JavaScript implementations; use getFullYear( ) instead.
Netscape implementations of JavaScript 1.0 through 1.2 subtract 1900 only for years between 1900 and 1999.
| Date.parse( ) | parse a date/time string |
JavaScript 1.0; JScript 1.0; ECMAScript v1
Date.parse(date)
The number of milliseconds between the specified date and time and midnight GMT on January 1, 1970.
Date.parse( ) is a static method of Date. It is always invoked through the Date constructor as Date.parse( ), not through a Date object as date.parse( ). Date.parse( ) takes a single string argument. It parses the date contained in this string and returns it in millisecond format, which can be used directly, used to create a new Date object, or used to set the date in an existing Date object with Date.setTime( ).
The ECMAScript standard does not specify the format of the strings that can be parsed by Date.parse( ) except to say that this method can parse the strings returned by the Date.toString( ) and Date.toUTCString( ) methods. Unfortunately, these functions format dates in an implementation-dependent way, so it is not in general possible to write dates in a way that is guaranteed to be understood by all JavaScript implementations.
| Date.setDate( ) | set the day of the month |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setDate(day_of_month)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
| Date.setFullYear( ) | set the year and, optionally, the month and date |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setFullYear(year) date.setFullYear(year, month) date.setFullYear(year, month, day)
The internal millisecond representation of the adjusted date.
| Date.setHours( ) | set the hours, minutes, seconds, and milliseconds fields of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setHours(hours) date.setHours(hours, minutes) date.setHours(hours, minutes, seconds) date.setHours(hours, minutes, seconds, millis)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
| Date.setMilliseconds( ) | set the milliseconds field of a Date |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setMilliseconds(millis)
The millisecond representation of the adjusted date.
| Date.setMinutes( ) | set the minutes and seconds fields of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setMinutes(minutes) date.setMinutes(minutes, seconds) date.setMinutes(minutes, seconds, millis)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
| Date.setMonth( ) | set the month and day fields of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setMonth(month) date.setMonth(month, day)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
| Date.setSeconds( ) | set the seconds and milliseconds fields of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setSeconds(seconds) date.setSeconds(seconds, millis)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
| Date.setTime( ) | set a Date in milliseconds |
JavaScript 1.0; JScript 1.0; ECMAScript v1
date.setTime(milliseconds)
The milliseconds argument. Prior to ECMAScript standardization, this method returns nothing.
| Date.setUTCDate( ) | set the day of the month (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCDate(day_of_month)
The internal millisecond representation of the adjusted date.
| Date.setUTCFullYear( ) | set the year, month, and day (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCFullYear(year) date.setUTCFullYear(year, month) date.setUTCFullYear(year, month, day)
The internal millisecond representation of the adjusted date.
| Date.setUTCHours( ) | set the hours, minutes, seconds, and milliseconds fields of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCHours(hours) date.setUTCHours(hours, minutes) date.setUTCHours(hours, minutes, seconds) date.setUTCHours(hours,minutes, seconds, millis)
The millisecond representation of the adjusted date.
| Date.setUTCMilliseconds( ) | set the milliseconds field of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCMilliseconds(millis)
The millisecond representation of the adjusted date.
| Date.setUTCMinutes( ) | set the minutes and seconds fields of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCMinutes(minutes) date.setUTCMinutes(minutes, seconds) date.setUTCMinutes(minutes, seconds, millis)
The millisecond representation of the adjusted date.
| Date.setUTCMonth( ) | set the month and day fields of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCMonth(month) date.setUTCMonth(month, day)
The millisecond representation of the adjusted date.
| Date.setUTCSeconds( ) | set the seconds and milliseconds fields of a Date (universal time) |
JavaScript 1.2; JScript 3.0; ECMAScript v1
date.setUTCSeconds(seconds) date.setUTCSeconds(seconds, millis)
The millisecond representation of the adjusted date.
| Date.setYear( ) | set the year field of a Date |
JavaScript 1.0; JScript 1.0; ECMAScript v1; deprecated by ECMAScript v3
date.setYear(year)
The millisecond representation of the adjusted date. Prior to ECMAScript standardization, this method returns nothing.
setYear( ) sets the year field of a specified Date object, with special behavior for years between 1900 and 1999.
As of ECMAScript v3, this function is no longer required in conforming JavaScript implementations; use setFullYear( ) instead.