[Contents] [Previous] [Next] [Last]


Chapter 3
Functions

This section describes the following new functions and features of functions:

Nesting Functions Within Functions

You can nest a function within a function. The nested function can use the arguments and variables of the outer function. The outer function cannot use the arguments and variables of the nested function.

Number

Core function. Converts the specified object to a number.

Syntax

Number(x)

Parameter

x is any object.

Description

When the object is a Date object, Number returns a value in milliseconds measured from 01 January, 1970 UTC (GMT), positive after this date, negative before.

Example

The following example converts the Date object to a numerical value:

<SCRIPT LANGUAGE="JavaScript1.2">
d = new Date ("December 17, 1995 03:24:00"); 
document.write (Number(d) + "<BR>");
</SCRIPT>

This prints "819199440000."

String

Core function. Converts the specified object to a string.

Syntax

String(x)

Parameter

x is any object.

Description

When the object is a Date object, String returns a string representation of the date. Its format is: Thu Aug 18 04:37:43 Pacific Daylight Time 1983.

Example

The following example converts the Date object to a readable string.

<SCRIPT LANGUAGE="JavaScript1.2">
D = new Date (430054663215); 
document.write (String(D) +" <BR>");
</SCRIPT>

This prints "Thu Aug 18 04:37:43 Pacific Daylight Time 1983."


[Contents] [Previous] [Next] [Last]

Last Updated: 10/22/97 11:48:02


Copyright © 1997 Netscape Communications Corporation