15 Native ECMAScript objects
There are certain built-in objects available whenever an ECMAScript program begins execution. One, the global object, is in the scope chain of the executing program. Others are accessible as initial properties of the global object.
Many built-in objects are functions: they can be invoked with arguments. Some of them furthermore are constructors: they are functions intended for use with the new operator. For each built-in function, this specification describes the arguments required by that function and properties of the function object. For each built-in constructor, this specification furthermore describes properties of the prototype object of that constructor and properties of specific object instances returned by a new expression that invokes that constructor.
Unless otherwise specified in the description of a particular function, if a function or constructor described in this section is given fewer arguments than the function is specified to require, the function or constructor shall behave exactly as if it had been given sufficient additional arguments, each such argument being the undefined value.
None of the built-in functions described in this section shall initially have an arguments property, nor is one ever automatically added during execution in the manner described for script functions in section 10.1.8.
Every built-in function and every built-in constructor has the Function prototype object, which is the value of the expression Function.prototype (15.3.3.1), as the value of its internal [[Prototype]] property, except the Function prototype object itself.
Every built-in prototype object has the Object prototype object, which is the value of the expression Object.prototype (15.2.3.1), as the value of its internal [[Prototype]] property, except the Object prototype object itself. Every native prototype object associated with a program-created function also has the Object prototype object as the value of its internal [[Prototype]] property.
None of the built-in functions described in this section shall implement the internal [[Construct]] method unless otherwise specified in the description of a particular function. None of the built-in functions described in this section shall initially have a prototype property unless otherwise specified in the description of a particular function.Every built-in function object described in this section—whether as a constructor, an ordinary function, or both—has a length property whose value is an integer. Unless otherwise specified, this value is equal to the number of named arguments shown in the section heading for the function description; for example, the function object that is the initial value of the indexOf property of the String prototype object is described under the section heading "indexOf(searchString, position)" which shows the two named arguments searchString and position ; therefore the value of the length property of that function object is 2 . Sometimes the same function object is described under more than one heading to emphasize its different behaviors when given different numbers of actual arguments; in such a case, unless otherwise specified, the length value is the largest number of arguments shown in any applicable section heading. For example, the function object that is the initial value of the Object property of the global object is described under four separate headings: as a function of one argument (section 15.2.1.1), as a function of zero arguments (section 15.2.1.2), as a constructor of one argument (15.2.2.1), and as a constructor of zero arguments (15.2.2.2). The largest number of arguments described is 1, so the value of the length property of that function object is 1 .
In every case, a length property of a built-in function object described in this section has the attributes { ReadOnly, DontDelete, DontEnum } (and no others). Every other property described in this section has the attribute { DontEnum } (and no others) unless otherwise specified.
15.1 The global object
The global object does not have a [[Construct]] property; it is not possible to use the global object as a constructor with the new operator.
The global object does not have a [[Call]] property; it is not possible to invoke the global object as a function.
The value of the [[Prototype]] property of the global object is implementation-dependent.
15.1.1 Value properties of the global object
15.1.1.1 NaN
The initial value of NaN is NaN .
15.1.1.2 Infinity
The initial value of Infinity is + ∞.
15.1.2 Function properties of the global object
15.1.2.1 eval(x)
When the eval function is called with one argument x , the following steps are taken:
- If x is not a string value, return x .
- Parse x as an ECMAScript Program . If the parse fails, generate a runtime error.
- Evaluate the program from step 2.
- If Result(3) is "normal completion after value V ", return the value V .
- Return undefined .
15.1.2.2 parseInt(string, radix)
The parseInt function produces an integer value dictated by intepretation of the contents of the string argument according to the specified radix .
When the parseInt function is called, the following steps are taken:
- Call ToString( string ).
- Compute a substring of Result(1) consisting of the leftmost character that is not a StrWhiteSpaceChar and all characters to the right of that character. (In other words, remove leading whitespace.)
- Let sign be 1.
- If Result(2) is not empty and the first character of Result(2) is a minus sign - , let sign be −1.
- If Result(2) is not empty and the first character of Result(2) is a plus sign + or a minus sign - , then Result(5) is the substring of Result(2) produced by removing the first character; otherwise, Result(5) is Result(2).
- If the radix argument is not supplied, go to step 12.
- Call ToInt32( radix ).
- If Result(7) is zero, go to step 12; otherwise, if Result(7) < 2 or Result(7) > 36, return NaN .
- Let R be Result(7).
- If R = 16 and the length of Result(5) is at least 2 and the first two characters of Result(5) are either " 0x " or " 0X ", let S be the substring of Result(5) consisting of all but the first two characters; otherwise, let S be Result(5).
- Go to step 22.
- If Result(5) is empty or the first character of Result(5) is not 0 , go to step 20.
- If the length of Result(5) is at least 2 and the second character of Result(5) is x or X , go to step 17.
- Let R be 8.
- Let S be Result(5).
- Go to step 22.
- Let R be 16.
- Let S be the substring of Result(5) consisting of all but the first two characters.
- Go to step 22.
- Let R be 10.
- Let S be Result(5).
- If S contains any character that is not a radix- R digit, then let Z be the substring of S consisting of all characters to the left of the leftmost such character; otherwise, let Z be S .
- If Z is empty, return NaN .
- Compute the mathematical integer value that is represented by Z in radix- R notation. (But if R is 10 and Z contains more than 20 significant digits, every digit after the 20th may be replaced by a 0 digit, at the option of the implementation; and if R is not 2, 4, 8, 10, 16, or 32, then Result(24) may be an implementation-dependent approximation to the mathematical integer value that is represented by Z in radix- R notation.)
- Compute the number value for Result(24).
- Return sign ⋅ Result(25).
Note that parseInt may interpret only a leading portion of the string as an integer value; it ignores any characters that cannot be interpreted as part of the notation of an integer, and no indication is given that any such characters were ignored.
15.1.2.3 parseFloat(string)
The parseFloat function produces a number value dictated by intepretation of the contents of the string argument as a decimal literal.
When the parseFloat function is called, the following steps are taken:
- Call ToString( string ).
- Compute a substring of Result(1) consisting of the leftmost character that is not a StrWhiteSpaceChar and all characters to the right of that character.(In other words, remove leading whitespace.)
- If neither Result(2) nor any prefix of Result(2) satisfies the syntax of a StrDecimalLiteral (see 9.3.1), return NaN .
- Compute the longest prefix of Result(2), which might be Result(2) itself, that satisfies the syntax of a StrDecimalLiteral .
- Return the number value for the MV of Result(4).
Note that parseFloat may interpret only a leading portion of the string as a number value; it ignores any characters that cannot be interpreted as part of the notation of an decimal literal, and no indication is given that any such characters were ignored.
15.1.2.4 escape(string)
The escape function computes a new version of a string value in which certain characters have been replaced by a hexadecimal escape sequence. The result thus contains no special characters that might have special meaning within a URL.
For characters whose Unicode encoding is 0xFF or less, a two-digit escape sequence of the form % xx is used in accordance with RFC1738. For characters whose Unicode encoding is greater than 0xFF , a four-digit escape sequence of the form %u xxxx is used
When the escape function is called with one argument string , the following steps are taken:
- Call ToString( string ).
- Compute the number of characters in Result(1).
- Let R be the empty string.
- Let k be 0.
- If k equals Result(2), return R .
- Get the character at position k within Result(1).
- If Result(6) is one of the 69 nonblank ASCII characters ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789 @*_+-./ , go to step 14.
- Compute the 16-bit unsigned integer that is the Unicode character encoding of Result(6).
- If Result(8), is less than 256, go to step 12.
- Let S be a string containing six characters " %u wxyz " where wxyz are four hexadecimal digits encoding the value of Result(8).
- Go to step 15.
- Let S be a string containing three characters " % xy " where xy are two hexadecimal digits encoding the value of Result(8).
- Go to step 15.
- Let S be a string containing the single character Result(6).
- Let R be a new string value computed by concatenating the previous value of R and S .
- Increase k by 1.
- Go to step 5.
15.1.2.5 unescape(string)
The unescape function computes a new version of a string value in which each escape sequences of the sort that might be introduced by the escape function is replaced with the character that it represents.
When the unescape function is called with one argument string , the following steps are taken:
- Call ToString( string ).
- Compute the number of characters in Result(1).
- Let R be the empty string.
- Let k be 0.
- If k equals Result(2), return R .
- Let c be the character at position k within Result(1).
- If c is not % , go to step 18.
- If k is greater than Result(2)−6, go to step 14.
- If the character at position k +1 within result(1) is not u , go to step 14.
- If the four characters at positions k +2, k +3, k +4, and k +5 within Result(1) are not all hexadecimal digits, go to step 14.
- Let c be the character whose Unicode encoding is the integer represented by the four hexadecimal digits at positions k +2, k +3, k +4, and k +5 within Result(1).
- Increase k by 5.
- Go to step 18.
- If k is greater than Result(2)−3, go to step 18.
- If the two characters at positions k +1 and k +2 within Result(1) are not both hexadecimal digits, go to step 18.
- Let c be the character whose Unicode encoding is the integer represented by two zeroes plus the two hexadecimal digits at positions k +1 and k +2 within Result(1).
- Increase k by 2.
- Let R be a new string value computed by concatenating the previous value of R and c .
- Increase k by 1.
- Go to step 5.
15.1.2.6 isNaN(number)
Applies ToNumber to its argument, then returns true if the result is NaN , and otherwise returns false .
15.1.2.7 isFinite(number)
Applies ToNumber to its argument, then returns false if the result is NaN , + ∞, or −∞, and otherwise returns true .
15.1.3 Constructor Properties of the Global Object
15.1.3.1 Object( . . . )
See sections 15.2.1 and 15.2.2.
15.1.3.2 Function( . . . )
See sections 15.3.1 and 15.3.2.
15.1.3.3 Array( . . . )
See section 15.4.1.
15.1.3.4 String( . . . )
See sections 15.5.1 and 15.5.2.
15.1.3.5 Boolean( . . . )
See sections 15.6.1 and 15,6,2.
15.1.3.6 Number( . . . )
See sections 15.7.1 and 15.7.2.
15.1.3.7 Date( . . . )
See section 15.9.2.
15.1.4 Other Properties of the Global Object
15.1.4.1 Math
See section 15.8.
15.2 Object Objects
15.2.1 The Object Constructor Called as a Function
When Object is called as a function rather than as a constructor, it performs a type conversion.
15.2.1.1 Object(value)
When the Object function is called with one argument value , the following steps are taken:
- If the value is null or undefined , create and return a newobject with no properties (other than internal properties) exactly as if the object constructor had been called on that same value (15.2.2.1).
- Return ToObject( value ).
15.2.1.2 Object()
When the Object function is called with no arguments, the following step is taken:
1. Create and return a newobject with no properties (other than internal properties) exactly if the object constructor had been called with no argument (15.2.2.2).
15.2.2 The Object Constructor
When Object is called as part of a new expression, it is a constructor that may create an object.
15.2.2.1 new Object(value)
When the Object constructor is called with one argument value , the following steps are taken:
- If the type of the value is not Object, go to step 4.
- If the value is a native ECMAScript object, do not create a new object; simply return value .
- If the value is a host object, then actions are taken and a result is returned in an implementation-dependent manner that may depend on the host object.
- If the type of the value is String, return ToObject( value ).
- If the type of the value is Boolean, return ToObject( value ).
- If the type of the value is Number, return ToObject( value ).
- (The type of the value must be Null or Undefined.) Create a new native ECMAScript object.
The [[Prototype]] property of the newly constructed object is set to the Object prototype object.
The [[Class]] property of the newly constructed object is set to "Object" .
The newly constructed object has no [[Value]] property.
Return the newly created native object.
15.2.2.2 new Object()
When the Object constructor is called with no argument, the following step is taken:
1. Create a new native ECMAScript object.
The [[Prototype]] property of the newly constructed object is set to the Object prototype object.
The [[Class]] property of the newly constructed object is set to "Object" .
The newly constructed object has no [[Value]] property.
Return the newly created native object.
15.2.3 Properties of the Object Constructor
The value of the internal [[Prototype]] property of the Object constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties and the length property, the Object constructor has the following properties:
15.2.3.1 Object.prototype
The initial value of Object.prototype is the built-in Object prototype object (15.2.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.2.4 Properties of the Object Prototype Object
The value of the internal [[Prototype]] property of the Object prototype object is null .
15.2.4.1 Object.prototype.constructor
The initial value of Object.prototype.constructor is the built-in Object constructor.
15.2.4.2 Object.prototype.toString()
When the toString method is called, the following steps are taken:
- Get the [[Class]] property of this object.
- Call ToString(Result(1)).
- Compute a string value by concatenating the three strings "[object " , Result(2), and "]" .
- Return Result(3).
15.2.4.3 Object.prototype.valueOf()
As a rule, the valueOf method for an object simply returns the object; but if the object is a "wrapper" for a host object, as may perhaps be created by the Object constructor (see section 15.2.2.1), then the contained host object should be returned.
15.2.5 Properties of Object Instances
Object instances have no special properties beyond those inherited from the Object prototype object.
15.3 Function Objects
15.3.1 The Function Constructor Called as a Function
When Function is called as a function rather than as a constructor, it creates and initializes a new function object. Thus the function call Function(...) is equivalent to the object creation expression new Function(...) with the same arguments.
15.3.1.1 Function(p1, p2, . . . , pn, body)
When the Function function is called with some arguments p1 , p2 , . . . , pn , body (where n might be 0, that is, there are no " p " arguments, and where body might also not be provided), the following steps are taken:
1. Create and return a new Function object exactly if the function constructor had been called with the same arguments (15.3.2.1).
15.3.2 The Function Constructor
When Function is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.3.2.1 new Function(p1, p2, . . . , pn, body)
The last argument specifies the body (executable code) of a function; any preceding arguments specify formal parameters.
When the Function constructor is called with some arguments p1 , p2 , . . . , pn , body (where n might be 0, that is, there are no " p " arguments, and where body might also not be provided), the following steps are taken:
- Let P be the empty string.
- If no arguments were given, let body be the empty string and go to step 13.
- If one argument was given, let body be that argument and go to step 13.
- Let Result(4) be the first argument.
- Let P be ToString(Result(4)).
- Let k be 2.
- If k equals the number of arguments, let body be the k 'th argument and go to step 13.
- Let Result(8) be the k 'th argument.
- Call ToString(Result(8)).
- Let P be the result of concatenating the previous value of P , the string "," (a comma), and Result(9).
- Increase k by 1.
- Go to step 7.
- Call ToString( body ).
- Let F be the newly constructed Function object.
- The [[Class]] property of F is set to "Function" .
- The [[Prototype]] property of F is set to the original Function prototype object, the one that is the initial value of Function.prototype (15.3.3.1) .
- Set the [[Call]] property of F to a method such that, when it is invoked, the executable function will be invoked whose formal parameters are specified by P and whose body is specified by Result(13). The string value P must be parsable as a FormalParameterListopt ; the string value result(13) must be parsable as a StatementListopt . (Note that both P and Result(13) may contain whitespace, line terminators, and comments.) However, if either P or Result(13) is syntactically incorrect, or otherwise cannot be interpreted as part of a correct ECMAScript function definition, then the [[Call]] property of F is not set and a runtime error is generated..
- Set the [[Construct]] property of F to a method that, when it is invoked, constructs a new object whose [[Prototype]] property is equal to the value of F .prototype at the time the [[Construct]] method is invoked (but if this value is not an object then the value of Object.prototype is used), then invokes F as a function (using its [[Call]] property) with the new object as the this value and the arguments given to the [[Construct]] method as the arguments. If the result of invoking the [[Call]] method is an object, that object becomes the result of the invocation of the [[Construct]] method; otherwise the new object becomes the result of the invocation of the [[Construct]] method.
- If the toString method of F is later invoked, it will use " anonymous " as the name of the function in rendering the function as a string.
- Compute, as an integer number value of positive sign, the number of formal parameters that resulted from the parse of P as a FormalParameterListopt .
- The length property of F is set to Result(20). This property is given attributes { DontDelete, DontEnum, ReadOnly }.
- Create a new object as if by the expression new Object() .
- The prototype property of F is set to Result(22). This property is given attributes { DontEnum }.
- The constructor property of Result(22) is set to F . This property is given attributes { DontEnum }.
- The arguments property of F is set to null . This property is given attributes { DontDelete, DontEnum, ReadOnly }.
Note that it is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the following expressions produce the same result:
new Function("a", "b", "c", "return a+b+c")
new Function("a, b, c", "return a+b+c")
new Function("a,b", "c", "return a+b+c")
A prototype property is automatically created for every function, against the possibility that the function will be used as a constructor.
15.3.3 Properties of the Function Constructor
15.3.3.1 Function.prototype
The initial value of Function.prototype is the built-in Function prototype object (15.3.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.3.3.2 Function.length
The length property is 1 . (Of course, the Function constructor accepts more than one argument, because it accepts a variable number of arguments.)
15.3.4 Properties of the Function Prototype Object
The Function prototype object is itself a Function object (its [[Class]] is "Function" ) that, when invoked, accepts any arguments and returns undefined .
The value of the internal [[Prototype]] property of the Function prototype object is the Object prototype object (15.2.3.1).
It is a function with an "empty body"; if it is invoked, it merely returns undefined .
The Function prototype object does not have a valueOf property of its own; however, it inherits the valueOf property from the Object prototype Object.
15.3.4.1 Function.prototype.constructor
The initial value of Function.prototype.constructor is the built-in Function constructor.
15.3.4.2 Function.prototype.toString()
An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration . Note in particular that the use and placement of whitespace, line terminators, and semicolons within the representation string is implementation-dependent.
The toString function is not generic; it generates a runtime error if its this value is not a Function object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.3.5 Properties of Function Instances
Every function instance has a [[Call]] property and a [[Construct]] property.
15.3.5.1 length
The value of the length property is usually an integer that indicates the "typical" number of arguments expected by the function. However, the language permits the function to be invoked with some other number
of arguments. The behavior of a function when invoked on a number of arguments other than the number specified by its length property depends on the function.
15.3.5.2 prototype
The value of the prototype property is used to initialize the internal [[Prototype]] property of a newly created object before the Function object is invoked as a constructor for that newly created object.
15.3.5.3 arguments
The value of the arguments property is normally null if there is no outstanding invocation of the function in progress (that is, the function has been called but has not yet returned). When a non-internal Function object (15.3.2.1) is invoked, its arguments property is "dynamically bound" to a newly created object that contains the arguments on which it was invoked (see 10.1.6 and 10.1.8). Note that the use of this property is discouraged; it is provided principally for compatibility with existing old code.
15.4 Array Objects
Array objects give special treatment to a certain class of property names. A property name P (in the form of a string value) is an array index if and only if ToString(ToUint32( P )) is equal to P and ToUint32( P ) is not equal to 2 32 −1. Every Array object has a length property whose value is always an integer with positive sign and less than 232. It is always the case that the length property is numerically greater than the name of every property whose name is an array index; whenever a property of an Array object is created or changed, other properties are adjusted as necessary to maintain this invariant. Specifically, whenever a property is added whose name is an array index, the length property is changed, if necessary, to be one more than the numeric value of that array index; and whenever the length property is changed, every property whose name is an array index whose value is not smaller than the new length is automatically deleted. This constraint applies only to properties of the Array object itself and is unaffected by length or array index properties that may be inherited from its prototype.
15.4.1 The Array Constructor Called as a Function
When Array is called as a function rather than as a constructor, it creates and initializes a new array object. Thus the function call Array (...) is equivalent to the object creation expression new Array (...) with the same arguments.
15.4.1.1 Array(item0, item1, . . .)
An array is created and returned as if by the expression new Array ( item0 , item1 , . . . ) .
15.4.1.2 Array(len)
An array is created and returned as if by the expression new Array ( len ) .
15.4.1.3 Array()
An array is created and returned as if by the expression new Array () .
15.4.2 The Array Constructor
When Array is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.4.2.1 new Array(item0, item1, . . .)
This description applies if and only if the Array constructor is given two or more arguments.
The [[Prototype]] property of the newly constructed object is set to the original Array prototype object, the one that is the initial value of Array.prototype (15.4.3.1) .
The [[Class]] property of the newly constructed object is set to "Array" .
The length property of the newly constructed object is set to the number of arguments.
The 0 property of the newly constructed object is set to item0 ; the 1 property of the newly constructed object is set to item1 ; and, in general, for as many arguments as there are, the k property of the newly constructed object is set to argument k , where the first argument is considered to be argument number 0 .
15.4.2.2 new Array(len)
The [[Prototype]] property of the newly constructed object is set to the original Array prototype object, the one that is the initial value of Array.prototype (0) .The [[Class]] property of the newly constructed object is set to "Array" .
If the argument len is a number, then the length property of the newly constructed object is set to ToUint32( len ). If the argument len is not a number, then the length property of the newly constructed object is set to 1 and the 0 property of the newly constructed object is set to len .
15.4.2.3 new Array()
The [[Prototype]] property of the newly constructed object is set to the original Array prototype object, the one that is the initial value of Array.prototype (15.4.3.1) .The [[Class]] property of the newly constructed object is set to "Array" .
The length property of the newly constructed object is set to +0 .
15.4.3 Properties of the Array Constructor
The value of the internal [[Prototype]] property of the Array constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties, the Array constructor has the following properties:
15.4.3.1 Array.prototype
The initial value of Array.prototype is the built-in Array prototype object (15.4.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.4.3.2 Array.length
The length property is 1 . (Of course, the Array constructor accepts more than one argument, because it accepts a variable number of arguments.)
15.4.4 Properties of the Array Prototype Object
The value of the internal [[Prototype]] property of the Array prototype object is the Object prototype object (15.2.3.1).
Note that the Array prototype object is itself an array; it has a length property (whose initial value is +0 ) and the special internal [[Put]] method described in section 15.4.5.1. In following descriptions of functions that are properties of the Array prototype object, the phrase "this object" refers to the object that is the this value for the invocation of the function. It is permitted for this to refer to an object for which the value of the internal [[Class]] property is not "Array" .
The Array prototype object does not have a valueOf property of its own; however, it inherits the valueOf property from the Object prototype Object.
15.4.4.1 Array.prototype.constructor
The initial value of Array.prototype.constructor is the built-in Array constructor.
15.4.4.2 Array.prototype.toString()
The elements of this object are converted to strings, and these strings are then concatenated, separated by comma characters. The result is the same as if the built-in join method were invoked for this object with no argument.
15.4.4.3 Array.prototype.join(separator)
The elements of the array are converted to strings, and these strings are then concatenated, separated by occurrences of the separator . If no separator is provided, a single comma is used as the separator.
When the join method is called with one argument separator , the following steps are taken:
- Call the [[Get]] method of this object with argument "length" .
- Call ToUint32(Result(1)).
- If separator is not supplied, let separator be the single-character string "," .
- Call ToString( separator ).
- If Result(2) is 0 , return the empty string.
- Call the [[Get]] method of this object with argument ToString( 0 ).
- If Result(6) is undefined or null , use the empty string; otherwise, call ToString(Result(6)).
- Let R be Result(7).
- Let k be 1 .
- If k equals Result(2), return R .
- Let S be a string value produced by concatenating R and Result(4).
- Call the [[Get]] method of this object with argument ToString( k ).
- If Result(12) is undefined or null , use the empty string; otherwise, call ToString(Result(12)).
- Let R be a string value produced by concatenating S and Result(13).
- Increase k by 1.
- Go to step 10.
Note that the join function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the join function can be applied successfully to a host object is implementation dependent .
15.4.4.4 Array.prototype.reverse()
The elements of the array are rearranged so as to reverse their order. This object is returned as the result of the call.
- Call the [[Get]] method of this object with argument "length" .
- Call ToUint32(Result(1)).
- Compute floor(Result(2)/2).
- Let k be 0 .
- If k equals Result(3), return this object.
- Compute Result(2)− k −1.
- Call ToString( k ).
- ToString(Result(6)).
- Call the [[Get]] method of this object with argument Result(7).
- Call the [[Get]] method of this object with argument Result(8).
- If this object has a property named by Result(8), go to step 12; but if this object has no property named by Result(8), then go to either step 12 or step 14, depending on the implementation.
- Call the [[Put]] method of this object with arguments Result(7) and Result(10).
- Go to step 15.
- Call the [[Delete]] method on this object, providing Result(7) as the name of the property to delete.
- If this object has a property named by Result(7), go to step 16; but if this object has no property named by Result(7), then go to either step 16 or step 18, depending on the implementation.
- Call the [[Put]] method of this object with arguments Result(8) and Result(9).
- Go to step 19.
- Call the [[Delete]] method on this object, providing Result(8) as the name of the property to delete.
- Increase k by 1.
- Go to step 5.
Note that the reverse function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the reverse function can be applied successfully to a host object is implementation dependent .
15.4.4.5 Array.prototype.sort(comparefn)
The elements of this array are sorted. The sort is not necessarily stable. If comparefn is provided, it should be a function that accepts two arguments x and y and returns a negative value if x < y , zero if x = y , or a positive value if x > y .
- Call the [[Get]] method of this object with argument "length" .
- Call ToUint32(Result(1)).
- Perform an implementation-dependent sequence of calls to the [[Get]] , [[Put]], and [[Delete]] methods of this object and toSortCompare (described below), where the first argument for each call to [[Get]], [[Put]] , or [[Delete]] is a nonnegative integer less than Result(2) and where the arguments for calls to SortCompare are results of previous calls to the [[Get]] method. After this sequence is complete, this object must have the following two properties.
- (1) There must be some mathematical permutation π of the nonnegative integers less than Result(2), such that for every nonnegative integer j less than Result(2), if property old[ j ] existed, then new[ π( j ) ] is exactly the same value as old[ j ], . but if property old[ j ] did not exist, then new[ π( j ) ] either does not exist or exists with value undefined .
- (2) If comparefn is not supplied or is a consistent comparison function for the elements of this array, then
for all nonnegative integers j and k , each less than Result(2), if old[ j ] compares less than old[ k ] (see SortCompare below), then π( j ) < π( k ).
Here we use the notation old[ j ] to refer to the hypothetical result of calling the [[Get]] method of this object with argument j before this step is executed, and the notation new[ j ] to refer to the hypothetical result of calling the [[Get]] method of this object with argument j after this step has been completely executed.
A function is a consistent comparison function for a set of values if (a) for any two of those values (possibly the same value) considered as an ordered pair, it always returns the same value when given that pair of values as its two arguments, and the result of applying ToNumber to this value is not NaN ; (b) when considered as a relation, where the pair ( x , y ) is considered to be in the relation if and only if applying the function to x and y and then applying ToNumber to the result produces a negative value, this relation is a partial order; and (c) when considered as a different relation, where the pair ( x , y ) is considered to be in the relation if and only if applying the function to x and y and then applying ToNumber to the result produces a zero value (of either sign), this relation is an equivalence relation. In this context, the phrase " x compares less than y " means applying Result(2) to x and y and then applying ToNumber to the result produces a negative value.
4. Return this object.
When the SortCompare operatoris called with two arguments x and y , the following steps are taken:
- If x and y are both undefined , return +0 .
- If x is undefined , return 1.
- If y is undefined , return −1.
- If the argument comparefn was not provided in the call to sort , go to step 7.
- Call comparefn with arguments x and y .
- Return Result(5).
- Call ToString( x ).
- Call ToString( y ).
- If Result(7) < Result(8), return −1.
- If Result(7) > Result(8), return 1.
- Return +0 .
Note that, because undefined always compared greater than any other value, undefined and nonexistent property values always sort to the end of the result. It is implementation-dependent whether or not such properties will exist or not at the end of the array when the sort is concluded.
Note that the sort function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the sort function can be applied successfully to a host object is implementation dependent .
15.4.5 Properties of Array Instances
Array instances inherit properties from the Array prototype object and also have the following properties.
15.4.5.1 [[Put]](P, V)
Array objects use a variation of the [[Put]] method used for other native ECMAScript objects (section 8.6.2.2).
Assume A is an Array object and P is a string.
When the [[Put]] method of A is called with property P and value V , the following steps are taken:
- Call the [[CanPut]] method of A with name P.
- If Result(1) is false, return.
- If A doesn't have a property with name P , go to step 7.
- If P is "length" , go to step 12.
- Set the value of property P of A to V .
- Go to step 8.
- Create a property with name P , set its value to V and give it empty attributes.
- If P is not an array index, return.
- If A itself has a property (not an inherited property) named "length" , andToUint32( P ) is less than the value of the length property of A , then return.
- Change (or set) the value of the length property of A to ToUint32( P )+1.
- Return.
- Compute ToUint32( V ).
- For every integer k that is less than the value of the length property of A but not less than Result(12), if A itself has a property (not an inherited property) named ToString( k ), then delete that property.
- Set the value of property P of A to Result(12).
- Return.
15.4.5.2 length
The length property of this Array object is always numerically greater than the name of every property whose name is an array index.
The length property has the attributes { DontEnum, DontDelete }.
15.5 String Objects
15.5.1 The String Constructor Called as a Function
When String is called as a function rather than as a constructor, it performs a type conversion.
15.5.1.1 String(value)
Returns a string value (not a String object) computed by ToString(value).
15.5.1.2 String()
Returns the empty string "" .
15.5.2 The String Constructor
When String is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.5.2.1 new String(value)
The [[Prototype]] property of the newly constructed object is set to the original String prototype object, the one that is the initial value of String.prototype (15.5.3.1) .
The [[Class]] property of the newly constructed object is set to "String" .
The [[Value]] property of the newly constructed object is set to ToString(value).
15.5.2.2 new String()
The [[Prototype]] property of the newly constructed object is set to the original String prototype object, the one that is the initial value of String.prototype (15.5.3.1) .
The [[Class]] property of the newly constructed object is set to "String" .
The [[Value]] property of the newly constructed object is set to the empty string.
15.5.3 Properties of the String Constructor
The value of the internal [[Prototype]] property of the String constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties and the length property, the String constructor has the following properties:
15.5.3.1 String.prototype
The initial value of String.prototype is the built-in String prototype object (15.5.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.5.3.2 String.fromCharCode(char0, char1, . . .)
Returns a string value containing as many characters asthe number of arguments. Each argument specifies one character of the resulting string, with the first argument specifying the first character, and so on, from left to right. An argument is converted to a character by applying the operation ToUint16 (section 9.7) and regarding the resulting 16-bit integer as the Unicode encoding of a character. If no arguments are supplied, the result is the empty string.
15.5.4 Properties of the String Prototype Object
The String prototype object is itself a String object (its [[Class]] is "String" ) whose value is an empty string.
The value of the internal [[Prototype]] property of the String prototype object is the Object prototype object (15.2.3.1).
In following descriptions of functions that are properties of the String prototype object, the phrase "this String object" refers to the object that is the this value for the invocation of the function; it is an error if this does not refer to an object for which the value of the internal [[Class]] property is "String" . Also, the phrase "this string value" refers to the string value represented by this String object, that is, the value of the internal [[Value]] property of this String object.
15.5.4.1 String.prototype.constructor
The initial value of String.prototype.constructor is the built-in String constructor.
15.5.4.2 String.prototype.toString()
Returns this string value. (Note that, for a String object, the toString method happens to return the same thing as the valueOf method.)
The toString function is not generic; it generates a runtime error if its this value is not a String object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15,5,4,3 String.prototype.valueOf()
Returns this string value.
The valueOf function is not generic; it generates a runtime error if its this value is not a String object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.5.4.4 String.prototype.charAt(pos)
Returns a string containing the character at position pos in this string. If there is no character at that position, the result is the empty string. The result is a string value, not a String object.
If pos is a value of Number type that is an integer, then the result of x.charAt( pos ) is equal to the result of x.substring( pos , pos +1) .
When the charAt method is called with one argument pos , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToInteger( pos ).
- Compute the number of characters in Result(1).
- If Result(2) is less than 0 or is not less than Result(3), return the empty string.
- Return a string of length 1, containing one character from Result(1), namely the character at position Result(2), where the first (leftmost) character in Result(1) is considered to be at position 0, the next one at position 1, and so on.
Note that the charAt function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.5 String.prototype.charCodeAt(pos)
Returns a number (a nonnegative integer less than 216) representing the Unicode encoding of the character at position pos in this string. If there is no character at that position, the result is NaN .
When the charCodeAt method is called with one argument pos , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToInteger( pos ).
- Compute the number of characters in Result(1).
- If Result(2) is less than 0 or is not less than Result(3), return NaN .
- Return a value of Number type, of positive sign, whose magnitude is the Unicode encoding of one character from Result(1), namely the character at position Result(2), where the first (leftmost) character in Result(1) is considered to be at position 0, the next one at position 1, and so on.
Note that the charCodeAt function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.6 String.prototype.indexOf(searchString, position)
If the given searchString appears as a substring of the result of converting this object to a string, at one or more positions that are at or to the right of the specified position, then the index of the leftmost such position is returned; otherwise -1 is returned. If position is undefined or not supplied, 0 is assumed, so as to search all of the string.
When the indexOf method is called with two arguments searchString and position , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToString( searchString ).
- Call ToInteger( position ). (If position is undefined or not supplied, this step produces the value 0 ).
- Compute the number of characters in Result(1).
- Compute min(max(Result(3), 0), Result(4)).
- Compute the number of characters in the string that is Result(2).
- Compute the smallest possible integer k not smaller than Result(5) such that k +Result(6) is not greater than Result(4), and for all nonnegative integers j less than Result(6), the character at position k + j of Result(1) is the same as the character at position j of Result(2); but if there is no such integer k , then compute the value -1 .
- Return Result(7).
Note that the indexOf function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.7 String.prototype.lastIndexOf(searchString, position)
If the given searchString appears as a substring of the result of converting this object to a string, at one or more positions that are at or to the left of the specified position, then the index of the rightmost such position is returned; otherwise -1 is returned. If position is undefined or not supplied, the length of this string value is assumed, so as to search all of the string.
When the lastIndexOf method is called with two arguments searchString and position , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToString( searchString ).
- Call ToNumber( position ). (If position is undefined or not supplied, this step produces the value NaN ).
- If Result(3) is NaN , use + ∞; otherwise, call ToInteger(Result(3)).
- Compute the number of characters in Result(1).
- Compute min(max(Result(4), 0), Result(5)).
- Compute the number of characters in the string that is Result(2).
- Compute the largest possible integer k not larger than Result(6) such that k +Result(7) is not greater than Result(5), and for all nonnegative integers j less than Result(7), the character at position k + j of Result(1) is the same as the character at position j of Result(2); but if there is no such integer k , then compute the value -1 .
- Return Result(8).
Note that the lastIndexOf function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.8 String.prototype.split(separator)
Returns an Array object into which substrings of the result of converting this object to a string have been stored. The substrings are determined by searching from left to right for occurrences of the given separator; these occurrences are not part of any substring in the returned array, but serve to divide up this string value. The separator may be a string of any length.
As a special case, if the separator is the empty string, the string is split up into individual characters; the length of the result array equals the length of the string, and each substring contains one character.
If the separator is not supplied, then the result array contains just one string, which is the string.
When the split method is called with one argument separator , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Create a new Array object of length 0 and call it A .
- If separator is not supplied, call the [[Put]] method of A with 0 and Result(1) as arguments, and then return A .
- Call ToString( separator ).
- Compute the number of characters in Result(1).
- Compute the number of characters in the string that is Result(4).
- Let p be 0 .
- If Result(6) is zero (the separator string is empty), go to step 17.
- Compute the smallest possible integer k not smaller than p such that k +Result(6) is not greater than Result(5), and for all nonnegative integers j less than Result(6), the character at position k + j of Result(1) is the same as the character at position j of Result(2); but if there is no such integer k , then go to step 14.
- Compute a string value equal to the substring of Result(1), consisting of the characters at positions p through k −1, inclusive.
- Call the [[Put]] method of A with A .length and Result(10) as arguments.
- Let p be k +Result(6).
- Go to step 9.
- Compute a string value equal to the substring of Result(1), consisting of the characters from position p to the end of Result(1).
- Call the [[Put]] method of A with A .length and Result(14) as arguments.
- Return A .
- If p equals Result(5), return A .
- Compute a string value equal to the substring of Result(1), consisting of the single character at position p .
- Call the [[Put]] method of A with A .length and Result(18) as arguments.
- Increase p by 1.
- Go to step 17.
Note that the split function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.9 String.prototype.substring(start)
Returns a substring of the result of converting this object to a string, starting from character position start and running to the end of the string. The result is a string value, not a String object.
If the argument is NaN or negative, it is replaced with zero; if the argument is larger than the length of the string, it is replaced with the length of the string.
When the substring method is called with one argument start , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToInteger( start ).
- Compute the number of characters in Result(1).
- Compute min(max(Result(2), 0), Result(3)).
- Return a string whose length is the difference between Result(3) and Result(4), containing characters from Result(1), namely the characters with indices Result(4) through Result(3)−1, in ascending order.
15.5.4.10 String.prototype.substring(start, end)
Returns a substring of the result of converting this object to a string, starting from character position start and running to character position end of the string. The result is a string value, not a String object.
If either argument is NaN or negative, it is replaced with zero; if either argument is larger than the length of the string, it is replaced with the length of the string.
If start is larger than end , they are swapped.
When the substring method is called with two arguments start and end , the following steps are taken:
- Call ToString, giving it the this value as its argument.
- Call ToInteger( start ).
- Call ToInteger ( end ).
- Compute the number of characters in Result(1).
- Compute min(max(Result(2), 0), Result(4)).
- Compute min(max(Result(3), 0), Result(4)).
- Compute min(Result(5), Result(6)).
- Compute max(Result(5), Result(6)).
- Return a string whose length is the difference between Result(8) and Result(7), containing characters from Result(1), namely the characters with indices Result(7) through Result(8)−1, in ascending order.
Note that the substring function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.11 String.prototype.toLowerCase
Returns a string equal in length to the length of the result of converting this object to a string. The result is a string value, not a String object.
Every character of the result is equal to the corresponding character of the string, unless that character has a Unicode 2.0 lowercase equivalent, in which case the lowercase equivalent is used instead. (The canonical Unicode 2.0 case mapping shall be used, which does not depend on implementation or locale.)
Note that the toLowerCase function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.4.12 String.prototype.toUpperCase
Returns a string equal in length to the length of the result of converting this object to a string. The result is a string value, not a String object.
Every character of the result is equal to the corresponding character of the string, unless that character has a Unicode 2.0 uppercase equivalent, in which case the uppercase equivalent is used instead. (The canonical Unicode 2.0 case mapping shall be used, which does not depend on implementation or locale.)
Note that the toUpperCase function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
15.5.5 Properties of String Instances
String instances inherit properties from the String prototype object and also have a [[Value]] property and a length property.
The [[Value]] property is the string value represented by this String object.
15.5.5.1 length
The number of characters in the String value represented by this String object.
Once a String object is created, this property is unchanging. It has the attributes { DontEnum, DontDelete, ReadOnly }.
15.6 Boolean Objects
15.6.1 The Boolean Constructor Called as a Function
When Boolean is called as a function rather than as a constructor, it performs a type conversion.
15.6.1.1 Boolean(value)
Returns a boolean value (not a Boolean object) computed by ToBoolean(value).
15.6.1.2 Boolean()
Returns false .
15.6.2 The Boolean Constructor
When Boolean is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.6.2.1 new Boolean(value)
The [[Prototype]] property of the newly constructed object is set to the original Boolean prototype object, the one that is the initial value of Boolean.prototype (15.6.3.1) .
The [[Class]] property of the newly constructed Boolean object is set to "Boolean" .
The [[Value]] property of the newly constructed Boolean object is set to ToBoolean(value).
15.6.2.2 new Boolean()
The [[Prototype]] property of the newly constructed object is set to the original Boolean prototype object, the one that is the initial value of Boolean.prototype (15.6.3.1) .
The [[Class]] property of the newly constructed Boolean object is set to "Boolean" .
The [[Value]] property of the newly constructed Boolean object is set to false .
15.6.3 Properties of the Boolean Constructor
The value of the internal [[Prototype]] property of the Boolean constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties and the length property, the Boolean constructor has the following property:
15.6.3.1 Boolean.prototype
The initial value of Boolean.prototype is the built-in Boolean prototype object (15.6.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.6.4 Properties of the Boolean Prototype Object
The Boolean prototype object is itself a Boolean object (its [[Class]] is "Boolean" ) whose value is false .
The value of the internal [[Prototype]] property of the Boolean prototype object is the Object prototype object (15.2.3.1).
In following descriptions of functions that are properties of the Boolean prototype object, the phrase "this Boolean object" refers to the object that is the this value for the invocation of the function; it is an error if this does not refer to an object for which the value of the internal [[Class]] property is "Boolean" . Also, the phrase "this boolean value" refers to the boolean value represented by this Boolean object, that is, the value of the internal [[Value]] property of this Boolean object.
15.6.4.1 Boolean.prototype.constructor
The initial value of Boolean.prototype.constructor is the built-in Boolean constructor.
15.6.4.2 Boolean.prototype.toString()
If this boolean value is true , then the string "true" is returned. Otherwise, this boolean value must be false , and the string "false" is returned.
The toString function is not generic; it generates a runtime error if its this value is not a Boolean object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.6.4.3 Boolean.prototype.valueOf()
Returns this boolean value.
The valueOf function is not generic; it generates a runtime error if its this value is not a Boolean object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.6.5 Properties of Boolean Instances
Boolean instances have no special properties beyond those inherited from the Boolean prototype object.
15.7 Number Objects
15.7.1 The Number Constructor Called as a Function
When Number is called as a function rather than as a constructor, it performs a type conversion.
15.7.1.1 Number(value)
Returns a number value (not a Number object) computed by ToNumber(value).
15.7.1.2 Number()
Returns +0 .
15.7.2 The Number Constructor
When Number is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.7.2.1 new Number(value)
The [[Prototype]] property of the newly constructed object is set to the original Number prototype object, the one that is the initial value of Number.prototype (0) .
The [[Class]] property of the newly constructed object is set to "Number" .
The [[Value]] property of the newly constructed object is set to ToNumber(value).
15.7.2.2 new Number()
The [[Prototype]] property of the newly constructed object is set to the original Number prototype object, the one that is the initial value of Number.prototype (15.7.3.1) .
The [[Class]] property of the newly constructed object is set to "Number" .
The [[Value]] property of the newly constructed object is set to +0 .
15.7.3 Properties of the Number Constructor
The value of the internal [[Prototype]] property of the Number constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties and the length property, the Number constructor has the following property:
15.7.3.1 Number.prototype
The initial value of Number.prototype is the built-in Number prototype object (15.7.4).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.3.2 Number.MAX_VALUE
The value of Number.MIN_VALUE is the largest positive finite value of the number type, which is approximately 1.7976931348623157e308 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.3.3 Number.MIN_VALUE
The value of Number.MIN_VALUE is the smallest positive nonzero value of the number type, which is approximately 5e-324 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.3.4 Number.NaN
The value of Number.NaN is NaN .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.3.5 Number.NEGATIVE_INFINITY
The value of Number.NEGATIVE_INFINITY is −∞.
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.3.6 Number.POSITIVE_INFINITY
The value of Number.POSITIVE_INFINITY is + ∞.
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.7.4 Properties of the Number Prototype Object
The Number prototype object is itself a Number object (its [[Class]] is "Number" ) whose value is +0 .
The value of the internal [[Prototype]] property of the Number prototype object is the Object prototype object (15.2.3.1).
In following descriptions of functions that are properties of the Number prototype object, the phrase "this Number object" refers to the object that is the this value for the invocation of the function; it is an error if
this does not refer to an object for which the value of the internal [[Class]] property is "Number" . Also, the phrase "this number value" refers to the number value represented by this Number object, that is, the value of the internal [[Value]] property of this Number object.
15.7.4.1 Number.prototype.constructor
The initial value of Number.prototype.constructor is the built-in Number constructor.
15.7.4.2 Number.prototype.toString(radix)
If the radix is the number 10 or not supplied, then this number value is given as an argument to the ToString operator; the resulting string value is returned.
If the radix is supplied and is an integer from 2 to 36, but not 10, the result is a string, the choice of which is implementation dependent.
The toString function is not generic; it generates a runtime error if its this value is not a Number object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.7.4.3 Number.prototype.valueOf()
Returns this number value.
The valueOf function is not generic; it generates a runtime error if its this value is not a Number object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.7.5 Properties of Number Instances
Number instances have no special properties beyond those inherited from the Number prototype object.
15.8 The Math Object
The Math object is merely a single object that has some named properties, some of which are functions.
The value of the internal [[Prototype]] property of the Math object is the Object prototype object (15.2.3.1).
The Math object does not have a [[Construct]] property; it is not possible to use the Math object as a constructor with the new operator.
The Math object does not have a [[Call]] property; it is not possible to invoke the Math object as a function.
Recall that, in this specification, the phrase "the number value for x " has a technical meaning defined in section8.5.
15.8.1 Value Properties of the Math Object
15.8.1.1 E
The number value for e , the base of the natural logarithms, which is approximately 2.7182818284590452354 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.2 LN10
The number value for the natural logarithm of 10, which is approximately 2.302585092994046 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.3 LN2
The number value for the natural logarithm of 2, which is approximately 0.6931471805599453 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.4 LOG2E
The number value for the base-2 logarithm of e , the base of the natural logarithms; this value is approximately 1.4426950408889634 . (Note that the value of Math.LOG2E is approximately the reciprocal of the value of Math.LN2 .)
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.5 LOG10E
The number value for the base-2 logarithm of e , the base of the natural logarithms; this value is approximately 0.4342944819032518 . (Note that the value of Math.LOG2E is approximately the reciprocal of the value of Math.LN2 .)
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.6 PI
The number value for π, the ratio of the circumference of a circle to its diameter, which is approximately 3.14159265358979323846 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.7 SQRT1_2
The number value for the square root of 1/2, which is approximately 0.7071067811865476 . (Note that the value of Math.SQRT1_2 is approximately the reciprocal of the value of Math.SQRT2 .)
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.1.8 SQRT2
The number value for the square root of 2, which is approximately 1.4142135623730951 .
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.8.2 Function Properties of the Math Object
Every function listed in this section applies the ToNumber operator to each of its arguments (in left-to-right order if there is more than one) and then performs a computation on the resulting number value(s).
The behavior of the functions acos , asin , atan , atan2 , cos , exp , log , pow , sin , and sqrt is not precisely specified here. They are intended to compute approximations to the results of familiar mathematical functions, but some latitude is allowed in the choice of approximation algorithms. The general intent is that an implementor should be able to use the same mathematical library for ECMAScript on a given hardware platform that is available to C programmers on that platform. Nevertheless, this specification recommends (though it does not require) the approximation algorithms for IEEE 754 arithmetic contained in fdlibm , the freely distributable mathematical library [XXXREF]. This specification also requires specific results for certain argument values that represent boundary cases of interest.
15.8.2.1 abs(x)
Returns the absolute value of its argument; in general, the result has the same magnitude as the argument but has positive sign.
- If the argument is NaN , the result is NaN .
- If the argument is − 0 , the result is +0 .
- If the argument is −∞, the result is + ∞.
15.8.2.2 acos(x)
Returns an implementation-dependent approximation to the arc cosine of the argument. The result is expressed in radians and ranges from +0 to +π.
- If the argument is NaN , the result is NaN .
- If the argument is greater than 1 , the result is NaN .
- If the argument is less than -1 , the result is NaN .
- If the argument is exactly 1 , the result is +0 .
15.8.2.3 asin(x)
Returns an implementation-dependent approximation to the arc sine of the argument. The result is expressed in radians and ranges from −π/2 to +π/2.
- If the argument is NaN , the result is NaN .
- If the argument is greater than 1 , the result is NaN .
- If the argument is less than -1 , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
15.8.2.4 atan(x)
Returns an implementation-dependent approximation to the arc tangent of the argument. The result is expressed in radians and ranges from −π/2 to +π/2.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞, the result is an implementation-dependent approximation to +π/2.
- If the argument is −∞, the result is an implementation-dependent approximation to −π/2.
15.8.2.5 atan2(y, x)
Returns an implementation-dependent approximation to the arc tangent of the quotient y/x of the arguments y and x , where the signs of the arguments are used to determine the quadrant of the result. Note that it is intentional and traditional for the two-argument arc tangent function that the argument named y be first and the argument named x be second. The result is expressed in radians and ranges from −π to +π.
- If either argument is NaN , the result is NaN .
- If y>0 and x is +0 , the result is an implementation-dependent approximation to +π/2.
- If y>0 and x is − 0 , the result is an implementation-dependent approximation to +π/2.
- If y is +0 and x>0 , the result is +0 .
- If y is +0 and x is +0 , the result is +0 .
- If y is +0 and x is − 0 , the result is an implementation-dependent approximation to +π.
- If y is +0 and x<0 , the result is an implementation-dependent approximation to +π.
- If y is − 0 and x>0 , the result is − 0 .
- If y is − 0 and x is +0 , the result is − 0 .
- If y is − 0 and x is − 0 , the result is an implementation-dependent approximation to −π.
- If y is − 0 and x<0 , the result is an implementation-dependent approximation to −π.
- If y<0 and x is +0 , the result is an implementation-dependent approximation to −π/2.
- If y<0 and x is − 0 , the result is an implementation-dependent approximation to −π/2.
- If y>0 and y is finite and x is + ∞, the result is +0 .
- If y>0 and y is finite and x is −∞, the result if an implementation-dependent approximation to +π.
- If y<0 and y is finite and x is + ∞, the result is − 0 .
- If y<0 and y is finite and x is −∞, the result is an implementation-dependent approximation to −π.
- If y is + ∞ and x is finite, the result is an implementation-dependent approximation to +π/2.
- If y is −∞ and x is finite, the result is an implementation-dependent approximation to −π/2.
- If y is + ∞ and x is + ∞, the result is an implementation-dependent approximation to +π/4.
- If y is + ∞ and x is −∞, the result is an implementation-dependent approximation to +3π/4.
- If y is −∞ and x is + ∞, the result is an implementation-dependent approximation to −π/4. • If y is −∞ and x is −∞, the result is an implementation-dependent approximation to −3π/4.
15.8.2.6 ceil(x)
Returns the smallest (closest to −∞) number value that is not less than the argument and is equal to a mathematical integer. If the argument is already an integer, the result is the argument itself.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞, the result is + ∞.
- If the argument is −∞, the result is −∞.
- If the argument is less than 0 but greater than -1 , the result is − 0 .
The value of Math.ceil(x) is the same as the value of -Math.floor(-x) .
15.8.2.7 cos(x)
Returns an implementation-dependent approximation to the cosine of the argument. The argument is expressed in radians.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is 1 .
- If the argument is − 0 , the result is 1 .
- If the argument is + ∞, the result is NaN .
- If the argument is −∞, the result is NaN .
15.8.2.8 exp(x)
Returns an implementation-dependent approximation to the exponential function of the argument ( e raised to the power of the argument, where e is the base of the natural logarithms).
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is 1 .
- If the argument is − 0 , the result is 1 .
- If the argument is + ∞, the result is + ∞.
- If the argument is −∞, the result is +0 .
15.8.2.9 floor(x)
Returns the greatest (closest to + ∞) number value that is not greater than the argument and is equal to a mathematical integer. If the argument is already an integer, the result is the argument itself.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞, the result is + ∞.
- If the argument is −∞, the result is −∞.
- If the argument is greater than 0 but less than 1 , the result is +0 .
The value of Math.floor(x) is the same as the value of -Math.ceil(-x) .
15.8.2.10 log(x)
Returns an implementation-dependent approximation to natural logarithm of the argument.
- If the argument is NaN , the result is NaN .
- If the argument is less than 0 , the result is NaN .
- If the argument is +0 or − 0 , the result is −∞.
- If the argument is 1 , the result is +0 .
- If the argument is + ∞, the result is + ∞.
15.8.2.11 max(x, y)
Returns the larger of the two arguments.
- If either argument is NaN , the result is NaN .
- If x>y , the result is x .
- If y>x , the result is y .
- If x is +0 and y is +0 , the result is +0 .
- If x is +0 and y is − 0 , the result is +0 .
- If x is − 0 and y is +0 , the result is +0 .
- If x is − 0 and y is − 0 , the result is − 0 .
15.8.2.12 min(x, y)
Returns the smaller of the two arguments.
- If either argument is NaN , the result is NaN .
- If x<y , the result is x .
- If y<x , the result is y .
- If x is +0 and y is +0 , the result is +0 .
- If x is +0 and y is − 0 , the result is − 0 .
- If x is − 0 and y is +0 , the result is − 0 .
- If x is − 0 and y is − 0 , the result is − 0 .
15.8.2.13 pow(x, y)
Returns an implementation-dependent approximation to the result of raising x to the power y .
- If y is NaN , the result is NaN .
- If y is +0 , the result is 1 , even if x is NaN .
- If y is − 0 , the result is 1 , even if x is NaN .
- If x is NaN and y is nonzero, the result is NaN .
- If abs(x)>1 and y is + ∞, the result is + ∞.
- If abs(x)>1 and y is −∞, the result is +0 .
- If abs(x)==1 and y is + ∞, the result is NaN .
- If abs(x)==1 and y is −∞, the result is NaN .
- If abs(x)<1 and y is + ∞, the result is +0 .
- If abs(x)<1 and y is −∞, the result is + ∞.
- If x is + ∞ and y>0 , the result is + ∞.
- If x is + ∞ and y<0 , the result is +0 .
- If x is −∞ and y>0 and y is an odd integer, the result is −∞.
- If x is −∞ and y>0 and y is not an odd integer, the result is + ∞.
- If x is −∞ and y<0 and y is an odd integer, the result is − 0 .
- If x is −∞ and y<0 and y is not an odd integer, the result is +0 .
- If x is +0 and y>0 , the result is +0 .
- If x is +0 and y<0 , the result is + ∞.
- If x is − 0 and y>0 and y is an odd integer, the result is − 0 .
- If x is − 0 and y>0 and y is not an odd integer, the result is +0 .
- If x is − 0 and y<0 and y is an odd integer, the result is −∞.
- If x is − 0 and y<0 and y is not an odd integer, the result is + ∞.
- If x<0 and x is finite and y is finite and y is not an integer, the result is NaN .
15.8.2.14 random()
Returns a number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudorandomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.
15.8.2.15 round(x)
Returns the number value that is closest to the argument and is equal to a mathematical integer. If two integer number values are equally close to the argument, then the result is the number value that is closer to + ∞. If the argument is already an integer, the result is the argument itself.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞, the result is + ∞.
- If the argument is −∞, the result is −∞.
- If the argument is greater than 0 but less than 0.5 , the result is +0 .
- If the argument is less than 0 but greater than or equal to -0.5 , the result is − 0 .
Note that Math.round(3.5) returns 4 , but Math.round(-3.5) returns -3 .
The value of Math.round(x) is the same as the value of Math.floor(x+0.5) , except when x is − 0 or is less than 0 but greater than or equal to -0.5 ; for these cases Math.round(x) returns − 0 , but Math.floor(x+0.5) returns +0 .
15.8.2.16 sin(x)
Returns an implementation-dependent approximation to the sine of the argument. The argument is expressed in radians.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞ or −∞, the result is NaN .
15.8.2.17 sqrt(x)
Returns an implementation-dependent approximation to the square root of the argument.
- If the argument is NaN , the result is NaN .
- If the argument less than 0 , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞, the result is + ∞.
15.8.2.18 tan(x)
Returns an implementation-dependent approximation to the tangent of the argument. The argument is expressed in radians.
- If the argument is NaN , the result is NaN .
- If the argument is +0 , the result is +0 .
- If the argument is − 0 , the result is − 0 .
- If the argument is + ∞ or −∞, the result is NaN .
15.9 Date Objects
15.9.1 Overview of Date Objects and Definitions of Internal Operators
A Date object contains a number indicating a particular instant in time to within a millisecond. The number may also be NaN , indicating that the Date object does not represent a specific instant of time.
The following sections define a number of functions for operating on time values. Note that, in every case, if any argument to such a function is NaN , the result will be NaN .
15.9.1.1 Time Range
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. Leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript number values can represent all integers from iMin = –9,007,199,254,740,991 to iMax = 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years, either forward or backward, from 01 January, 1970 UTC.
The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC. This span easily covers all of recorded human history and a fair amount of unrecorded human history.
The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0 .
15.9.1.2 Day Number and Time within Day
A given time value t belongs to day number
Day(t) = floor(t / msPerDay)
where the number of milliseconds per day is
msPerDay = 86400000
The remainder is called the time within the day:
TimeWithinDay( t ) = t modulo msPerDay
15.9.1.3 Year Number
ECMAScript uses an extrapolated Gregorian system to map a day number to a year number and to determine the month and date within that year. In this system, leap years are precisely those which are (divisible by 4) and ((not divisible by 100) or (divisible by 400)). The number of days in year number y is therefore defined by
DaysInYear(y) = 365 if (y modulo 4) ≠ 0
= 366 if (y modulo 4) = 0 and (y modulo 100) ≠ 0
= 365 if (y modulo 100) = 0 and (y modulo 400) ≠ 0
= 366 if (y modulo 400) = 0
Of course all non-leap years have 365 days with the usual number of days per month and leap years have an extra day in February. The day number of the first day of year y is given by:
DayFromYear(y) = 365⋅(y−1970) + floor((y−1969)/4) − floor((y−1901)/100) + floor((y−1601)/400)
The time value of the start of a year is:
TimeFromYear(y)= msPerDay⋅DayFromYear(y)
A time value determines a year by:
YearFromTime( t ) = the largest integer y (closest to positive infinity) such that TimeFromYear( y ) ≤ t
The leap-year function is 1 for a time within a leap year and otherwise is zero:
InLeapYear(t) = 0 if DaysInYear(YearFromTime(t)) = 365
= 1 if DaysInYear(YearFromTime(t)) = 36615.9.1.4 Month Number
Months are identified by an integer in the range 0 to 11, inclusive. The mapping MonthFromTime( t ) from a time value t to a month number is defined by:
MonthFromTime(t) = 0 if 0 ≤ DayWithinYear(t) < 31
= 1 if 31 ≤ DayWithinYear (t) < 59+InLeapYear(t)
= 2 if 59+InLeapYear(t) ≤ DayWithinYear (t) < 90+InLeapYear(t)
= 3 if 90+InLeapYear(t) ≤ DayWithinYear (t) < 120+InLeapYear(t)
= 4 if 120+InLeapYear(t) ≤ DayWithinYear (t) < 151+InLeapYear(t)
= 5 if 151+InLeapYear(t) ≤ DayWithinYear (t) < 181+InLeapYear(t)
= 6 if 181+InLeapYear(t) ≤ DayWithinYear (t) < 212+InLeapYear(t)
= 7 if 212+InLeapYear(t) ≤ DayWithinYear (t) < 243+InLeapYear(t)
= 8 if 243+InLeapYear(t) ≤ DayWithinYear (t) < 273+InLeapYear(t)
= 9 if 273+InLeapYear(t) ≤ DayWithinYear (t) < 304+InLeapYear(t)
= 10 if 304+InLeapYear(t) ≤ DayWithinYear (t) < 334+InLeapYear(t)
= 11 if 334+InLeapYear(t) ≤ DayWithinYear (t) < 365+InLeapYear(t)
where
DayWithinYear(t)= Day(t)−DayFromYear(YearFromTime(t))
A month value of 0 specifies January; 1 specifies February; 2 specifies March; 3 specifies April; 4 specifies May; 5 specifies June; 6 specifies July; 7 specifies August; 8 specifies September; 9 specifies October; 10 specifies November; and 11 specifies December. Note that MonthFromTime(0) = 0, corresponding to Thursday, 01 January, 1970.
15.9.1.5 Date Number
A date number is identified by an integer in the range 1 through 31, inclusive. The mapping DateFromTime( t ) from a time value t to a month number is defined by:
DateFromTime(t) = DayWithinYear(t)+1 if MonthFromTime(t)=0
= DayWithinYear(t)−30 if MonthFromTime(t)=1
= DayWithinYear(t)−58−InLeapYear(t) if MonthFromTime(t)=2
= DayWithinYear(t)−89−InLeapYear(t) if MonthFromTime(t)=3
= DayWithinYear(t)−119−InLeapYear(t) if MonthFromTime(t)=4
= DayWithinYear(t)−150−InLeapYear(t) if MonthFromTime(t)=5
= DayWithinYear(t)−180−InLeapYear(t) if MonthFromTime(t)=6
= DayWithinYear(t)−211−InLeapYear(t) if MonthFromTime(t)=7
= DayWithinYear(t)−242−InLeapYear(t) if MonthFromTime(t)=8
= DayWithinYear(t)−272−InLeapYear(t) if MonthFromTime(t)=9
= DayWithinYear(t)−303−InLeapYear(t) if MonthFromTime(t)=10
= DayWithinYear(t)−333−InLeapYear(t) if MonthFromTime(t)=1115.9.1.6 Week Day
The week day for a particular time value t is defined as
WeekDay( t ) = (Day( t ) + 4) modulo 7
A weekday value of 0 specifies Sunday; 1 specifies Monday; 2 specifies Tuesday; 3 specifies Wednesday; 4 specifies Thursday; 5 specifies Friday; and 6 specifies Saturday. Note that WeekDay(0) = 4, corresponding to Thursday, 01 January, 1970.
15.9.1.7 Local Time Zone Adjustment
An implementation of ECMAScript is expected to determine the local time zone adjustment by whatever means are available. The local time zone adjustment is a value LocalTZA measured in milliseconds which when added to UTC represents the local standard time. Daylight saving time is not reflected by LocalTZA. The value LocalTZA does not vary with time but depends only on the geographic location.
15.9.1.8 Daylight Saving Time Adjustment
An implementation of ECMAScript is expected to determine the daylight saving time algorithm by whatever means are available. The algorithm to determine the daylight saving time adjustment DaylightSavingTA( t ), measured in milliseconds, must depend only on four things:
(1) the time since the beginning of the year
t – TimeFromYear(YearFromTime(t))
(2) whether t is in a leap year
InLeapYear( t )
(3) the week day of the beginning of the year
WeekDay(TimeFromYear(YearFromTime( t ))
and (4) the geographic location.
The implementation of ECMAScript should not try to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the USA observed daylight saving time year round.
If the underlying operating system provides functionality for determining daylight saving time, the implementation of ECMAScript is free to map the year in question to an equivalent year (same leap-year-ness and same starting week day for the year) for which the operating system provides daylight saving time information. The only restriction is that all equivalent years should produce the same result.
15.9.1.9 Local Time
Conversion from UTC to local time is defined by
LocalTime(t) = t + LocalTZA + DaylightSavingTA(t)
Conversion from local time to UTC is defined by
UTC(t) = t – LocalTZA – DaylightSavingTA (t – LocalTZA)
Note that UTC(LocalTime( t )) is not necessarily always equal to t .
15.9.1.10 Hours, Minutes, Second, and Milliseconds
The following functions are useful in decomposing time values:
HourFromTime( t ) = floor( t / msPerHour) modulo HoursPerDay
MinFromTime( t ) = floor( t / msPerMinute) modulo MinutesPerHour
SecFromTime( t ) = floor( t / msPerSecond) modulo SecondsPerMinute
msFromTime( t ) = t modulo msPerSecond
where
HoursPerDay = 24
MinutesPerHour = 60
SecondsPerMinute = 60
msPerSecond = 1000
msPerMinute = msPerSecond ⋅ SecondsPerMinute = 60000
msPerHour = msPerMinute ⋅ MinutesPerHour = 3600000
15.9.1.11 MakeTime(hour, min, sec, ms)
The operator MakeTime calculates a number of milliseconds from its four arguments, which must be ECMAScript number values. This operator functions as follows:
- If hour is not finite or min is not finite or sec is not finite or ms is not finite, return NaN .
- Call ToInteger( hour ).
- Call ToInteger( min ).
- Call ToInteger( sec ).
- Call ToInteger( ms ).
- Compute Result(2) * msPerHour + Result(3) * msPerMinute + Result(4) * msPerSecond + Result(5), performing the arithmetic according to IEEE 754 rules (that is, as if using the ECMAScript operators * and + ).
- Return Result(6).
15.9.1.12 MakeDay(year, month, date)
The operator MakeDay calculates a number of days from its three arguments, which must be ECMAScript number values. This operator functions as follows:
- If year is not finite or month is not finite or date is not finite, return NaN .
- Call ToInteger( year ).
- Call ToInteger( month ).
- Call ToInteger( date ).
- Compute Result(2) + floor(Result(3)/12).
- Compute Result(3) modulo 12.
- Find a value t such that YearFromTime( t ) == Result(5) and MonthFromTime( t ) == Result(6) and DateFromTime( t ) == 1; but if this is not possible (because some argument is out of range), return NaN .
- Compute Day(Result(7)) + Result(4) − 1.
- Return Result(8).
15.9.1.13 MakeDate(day, time)
The operator MakeDate calculates a number of milliseconds from its two arguments, which must be ECMAScript number values. This operator functions as follows:
- If day is not finite or time is not finite, return NaN .
- Compute day ⋅ msPerDay + time .
- Return Result(2).
15.9.1.14 TimeClip(time)
The operator TimeClip calculates a number of milliseconds from its argument, which must be an ECMAScript number value. This operator functions as follows:
- If time is not finite, return NaN .
- If abs(Result(1)) > 8.64e15 (that is, 8.64 ⋅ 1015), return NaN .
- Return an implementation dependent choice of either ToInteger(Result(2)) or ToInteger(Result(2)) + ( +0 ). (Adding a positive zero converts − 0 to +0 .)
The point of step 3 is that an implementation is permitted a choice of internal representations of time values, for example as a 64-bit signed integer or as a 64-bit floating-point value. Depending on the implementation, this internal representation may or may not distinguish − 0 and +0 .
15.9.2 The Date Constructor Called As a Function
When Date is called as a function rather than as a constructor, it returns a string representing the current time (UTC). Note that the function call Date (...) is not equivalent to the object creation expression new Date (...) with the same arguments.
15.9.2.1 Date(year, month, date, hours, minutes, seconds, ms)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.2 Date(year, month, date, hours, minutes, seconds)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.3 Date(year, month, date, hours, minutes)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.4 Date(year, month, date, hours)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.5 Date(year, month, day)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.6 Date(year, month)
The arguments are accepted but are completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.7 Date(value)
The argument is accepted but is completely ignored. A string is created and returned as if by the expression (new Date ()).toString() .
15.9.2.8 Date()
A string is created and returned as if by the expression new Date ().toString() .
15.9.3 The Date Constructor
When Date is called as part of a new expression, it is a constructor: it initializes the newly created object.
15.9.3.1 new Date(year, month, date, hours, minutes, seconds, ms)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- Call ToNumber( seconds ).
- Call ToNumber( ms ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(8) is 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1).
- Compute MakeDay(Result(8), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), Result(6), Result(7)).
- Compute MakeDate(Result(9), Result(10)).
- Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(11))).
15.9.3.2 new Date(year, month, date, hours, minutes, seconds)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- Call ToNumber( seconds ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(7) is 1900+ToInteger(Result(1)); otherwise, Result(7) is Result(1).
- Compute MakeDay(Result(7), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), Result(6), 0).
- Compute MakeDate(Result(8), Result(9)).
- Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(10))).
15.9.3.3 new Date(year, month, date, hours, minutes)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(6) is 1900+ToInteger(Result(1)); otherwise, Result(6) is Result(1).
- Compute MakeDay(Result(6), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), 0, 0).
- Compute MakeDate(Result(7), Result(8)).
- Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(9))).
15.9.3.4 new Date(year, month, date, hours)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(5) is 1900+ToInteger(Result(1)); otherwise, Result(5) is Result(1).
- Compute MakeDay(Result(5), Result(2), Result(3)).
- Compute MakeTime(Result(4), 0, 0, 0).
- Compute MakeDate(Result(6), Result(7)).
- Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(8))).
15.9.3.5 new Date(year, month, day)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(4) is 1900+ToInteger(Result(1)); otherwise, Result(4) is Result(1).
- Compute MakeDay(Result(4), Result(2), Result(3)).
- Compute MakeDate(Result(5), 0).
- Set the [[Value]] property of the newly constructed object to TimeClip(UTC(Result(6))).
15.9.3.6 new Date(year, month)
The behavior of the Date constructor with two arguments is implementation dependent.
15.9.3.7 new Date(value)
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set as follows:
- Call ToPrimitive(value).
- If Type(Result(1)) is String, then go to step 5.
- Let V be ToNumber(Result(1)).
- Set the [[Value]] property of the newly constructed object to TimeClip(V) and return.
- Parse Result(1) as a date, in exactly the same manner as for the parse method (15.9.4.2); let V be the time value for this date.
- Go to step 4.
15.9.3.8 new Date()
The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1) .
The [[Class]] property of the newly constructed object is set to "Date" .
The [[Value]] property of the newly constructed object is set to the current time (UTC).
15.9.4 Properties of the Date Constructor
The value of the internal [[Prototype]] property of the Date constructor is the Function prototype object.
Besides the internal [[Call]] and [[Construct]] properties and the length property (whose value is 7 ), the Date constructor has the following properties:
15.9.4.1 Date.prototype
The initial value of Date.prototype is the built-in Date prototype object (15.9.5).
This property shall have the attributes { DontEnum, DontDelete, ReadOnly }.
15.9.4.2 Date.parse(string)
The parse function applies the ToString operator to its argument and interprets the resulting string as a date; it returns a number, the UTC time value corresponding to the date. The string may be interpreted as a local time, a UTC time, or a time in some other time zone, depending on the contents of the string.
If x is any Date object whose milliseconds amount is zero within a particular implementation of ECMAScript, then all of the following expressions should produce the same numeric value in that implementation, if all the properties referenced have their initial values:
x.valueOf() Date.parse(x.toString()) Date.parse(x.toGMTString())
However, the expression
Date.parse(x.toLocaleString())
is not required to produce the same number value as the preceding three expressions and, in general, the value produced by Date.parse is implementation dependent when given any string value that could not be produced in that implementation by the toString or toGMTString method.
15.9.4.3 Date.UTC(year, month, date, hours, minutes, seconds, ms)
When the UTC function is called with seven arguments, the following steps are taken:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- Call ToNumber( seconds ).
- Call ToNumber( ms ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(8) is 1900+ToInteger(Result(1)); otherwise, Result(8) is Result(1).
- Compute MakeDay(Result(8), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), Result(6), Result(7)).
- Return TimeClip(MakeDate(Result(9), Result(10))).
The UTC function differs from the Date constructor in two ways: it returns a time value as a number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
15.9.4.4 Date.UTC(year, month, date, hours, minutes, seconds)
When the UTC function is called with six arguments, the following steps are taken:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- Call ToNumber( seconds ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(7) is 1900+ToInteger(Result(1)); otherwise, Result(7) is Result(1).
- Compute MakeDay(Result(7), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), Result(6), 0).
- Return TimeClip(MakeDate(Result(8), Result(9))).
The UTC function differs from the Date constructor in two ways: it returns a time value as a number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
15.9.4.5 Date.UTC(year, month, date, hours, minutes)
When the UTC function is called with five arguments, the following steps are taken:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- Call ToNumber( minutes ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(6) is 1900+ToInteger(Result(1)); otherwise, Result(6) is Result(1).
- Compute MakeDay(Result(6), Result(2), Result(3)).
- Compute MakeTime(Result(4), Result(5), 0, 0).
- Return TimeClip(MakeDate(Result(7), Result(8))).
The UTC function differs from the Date constructor in two ways: it returns a time value as a number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
15.9.4.6 Date.UTC(year, month, date, hours)
When the UTC function is called with four arguments, the following steps are taken:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- Call ToNumber( hours ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(5) is 1900+ToInteger(Result(1)); otherwise, Result(5) is Result(1).
- Compute MakeDay(Result(5), Result(2), Result(3)).
- Compute MakeTime(Result(4), 0, 0, 0).
- Return TimeClip(MakeDate(Result(6), Result(7))).
The UTC function differs from the Date constructor in two ways: it returns a time value as a number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
15.9.4.7 Date.UTC(year, month, date)
When the UTC function is called with three arguments, the following steps are taken:
- Call ToNumber( year ).
- Call ToNumber( month ).
- Call ToNumber( date ).
- If Result(1) is not NaN and 0 ≤ ToInteger(Result(1)) ≤ 99, Result(4) is 1900+ToInteger(Result(1)); otherwise, Result(4) is Result(1).
- Compute MakeDay(Result(4), Result(2), Result(3)).
- Return TimeClip(MakeDate(Result(5), 0)).
The UTC function differs from the Date constructor in two ways: it returns a time value as a number, rather than creating a Date object, and it interprets the arguments in UTC rather than as local time.
15.9.4.8 Date.UTC(year, month)
The behavior of the UTC function with two arguments is implementation dependent.
15.9.4.9 Date.UTC(year)
The behavior of the UTC function with one argument is implementation dependent.
15.9.4.10 Date.UTC()
The behavior of the UTC function with no arguments is implementation dependent.
15.9.5 Properties of the Date Prototype Object
The Date prototype object is itself a Date object (its [[Class]] is "Date" ) whose value is NaN .
The value of the internal [[Prototype]] property of the Date prototype object is the Object prototype object (15.2.3.1).
In following descriptions of functions that are properties of the Date prototype object, the phrase "this Date object" refers to the object that is the this value for the invocation of the function; it is an error if this does not refer to an object for which the value of the internal [[Class]] property is "Date" . Also, the phrase "this time value" refers to the number value for the time represented by this Date object, that is, the value of the internal [[Value]] property of this Date object.
15.9.5.1 Date.prototype.constructor
The initial value of Date.prototype.constructor is the built-in Date constructor.
15.9.5.2 Date.prototype.toString()
This function returns a string value. The contents of the string are implementation dependent, but are intended to represent the Date in a convenient, human-readable form in the current time zone.
The toString function is not generic; it generates a runtime error if its this value is not a Date object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.9.5.3 Date.prototype.valueOf()
The valueOf function returns a number, which is this time value.
The valueOf function is not generic; it generates a runtime error if its this value is not a Date object. Therefore it cannot be transferred to other kinds of objects for use as a method.
15.9.5.4 Date.prototype.getTime()
- If the this value is not an object whose [[Class]] property is "Date" , generate a runtime error.
- Return this time value.
15.9.5.5 Date.prototype.getYear()
This function is specified here for backwards compatibility only. The function getFullYear is much to be preferred for nearly all purposes, because it avoids the "year 2000 problem."
- Let t be this time value.
- If t is NaN , return NaN .
- Return YearFromTime(LocalTime( t )) − 1900.
15.9.5.6 Date.prototype.getFullYear()
- Let t be this time value.
- If t is NaN , return NaN .
- Return YearFromTime(LocalTime( t )).
15.9.5.7 Date.prototype.getUTCFullYear()
- Let t be this time value.
- If t is NaN , return NaN .
- Return YearFromTime( t ).
15.9.5.8 Date.prototype.getMonth()
- Let t be this time value.
- If t is NaN , return NaN .
- Return MonthFromTime(LocalTime( t )).
15.9.5.9 Date.prototype.getUTCMonth()
- Let t be this time value.
- If t is NaN , return NaN .
- Return MonthFromTime( t ).
15.9.5.10 Date.prototype.getDate()
- Let t be this time value.
- If t is NaN , return NaN .
- Return DateFromTime(LocalTime( t )).
15.9.5.11 Date.prototype.getUTCDate()
- Let t be this time value.
- If t is NaN , return NaN .
- Return DateFromTime( t ).
15.9.5.12 Date.prototype.getDay()
- Let t be this time value.
- If t is NaN , return NaN .
- Return WeekDay(LocalTime( t )).
15.9.5.13 Date.prototype.getUTCDay()
- Let t be this time value.
- If t is NaN , return NaN .
- Return WeekDay( t ).
15.9.5.14 Date.prototype.getHours()
- Let t be this time value.
- If t is NaN , return NaN .
- Return HourFromTime(LocalTime( t )).
15.9.5.15 Date.prototype.getUTCHours()
- Let t be this time value.
- If t is NaN , return NaN .
- Return HourFromTime( t ).
15.9.5.16 Date.prototype.getMinutes()
- Let t be this time value.
- If t is NaN , return NaN .
- Return MinFromTime(LocalTime( t )).
15.9.5.17 Date.prototype.getUTCMinutes()
- Let t be this time value.
- If t is NaN , return NaN .
- Return MinFromTime( t ).
15.9.5.18 Date.prototype.getSeconds()
- Let t be this time value.
- If t is NaN , return NaN .
- Return SecFromTime(LocalTime( t )).
15.9.5.19 Date.prototype.getUTCSeconds()
- Let t be this time value.
- If t is NaN , return NaN .
- Return SecFromTime( t ).
15.9.5.20 Date.prototype.getMilliseconds()
- Let t be this time value.
- If t is NaN , return NaN .
- Return msFromTime(LocalTime( t )).
15.9.5.21 Date.prototype.getUTCMilliseconds()
- Let t be this time value.
- If t is NaN , return NaN .
- Return msFromTime( t ).
15.9.5.22 Date.prototype.getTimezoneOffset()
Returns the difference between local time and UTC time in minutes.
- Let t be this time value.
- If t is NaN , return NaN .
3. Return ( t − LocalTime( t )) / msPerMinute.
15.9.5.23 Date.prototype.setTime(time)
- If the this value is not a Date object, generate a runtime error.
- Call ToNumber( time ).
- Call TimeClip(Result(1)).
- Set the [[Value]] property of the this value to Result(2).
- Return the value of the [[Value]] property of the this value.
15.9.5.24 Date.prototype.setMilliseconds(ms)
- Let t be the result of LocalTime(this time value).
- Call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), MinFromTime( t ), SecFromTime( t ), Result(2)).
- Compute UTC(MakeDate(Day( t ), Result(3))).
- Set the [[Value]] property of the this value to TimeClip(Result(4)).
- Return the value of the [[Value]] property of the this value.
15.9.5.25 Date.prototype.setUTCMilliseconds(ms)
- Let t be this time value.
- Call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), MinFromTime( t ), SecFromTime( t ), Result(2)).
- Compute MakeDate(Day( t ), Result(3)).
- Set the [[Value]] property of the this value to TimeClip(Result(4)).
- Return the value of the [[Value]] property of the this value.
15.9.5.26 Date.prototype.setSeconds(sec [, ms ] )
If ms is not specified, this behaves as if ms were specified with the value getMilliseconds( ).
- Let t be the result of LocalTime(this time value).
- Call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), MinFromTime( t ), Result(2), Result(3)).
- Compute UTC(MakeDate(Day( t ), Result(4))).
- Set the [[Value]] property of the this value to TimeClip(Result(5)).
- Return the value of the [[Value]] property of the this value.
15.9.5.27 Date.prototype.setUTCSeconds(sec [, ms ] )
If ms is not specified, this behaves as if ms were specified with the value getUTCMilliseconds( ).
- Let t be this time value.
- Call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), MinFromTime( t ), Result(2), Result(3)).
- Compute MakeDate(Day( t ), Result(4)).
- Set the [[Value]] property of the this value to TimeClip(Result(5)).
- Return the value of the [[Value]] property of the this value.
15.9.5.28 Date.prototype.setMinutes(min [, sec [, ms ]] )
If sec is not specified, this behaves as if sec were specified with the value getSeconds ( ).
If ms is not specified, this behaves as if ms were specified with the value getMilliseconds( ).
- Let t be the result of LocalTime(this time value).
- Call ToNumber( min ).
- If sec is not specified, compute SecFromTime( t ); otherwise, call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), Result(2), Result(3), Result(4)).
- Compute UTC(MakeDate(Day( t ), Result(5))).
- Set the [[Value]] property of the this value to TimeClip(Result(6)).
- Return the value of the [[Value]] property of the this value.
15.9.5.29 Date.prototype.setUTCMinutes(min [, sec [, ms ]] )
If sec is not specified, this behaves as if sec were specified with the value getUTCSeconds ( ).
If ms is not specified, this behaves as if ms were specified with the value getUTCMilliseconds( ).
- Let t be this time value.
- Call ToNumber( min ).
- If sec is not specified, compute SecFromTime( t ); otherwise, call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(HourFromTime( t ), Result(2), Result(3), Result(4)).
- Compute MakeDate(Day( t ), Result(5)).
- Set the [[Value]] property of the this value to TimeClip(Result(6)).
- Return the value of the [[Value]] property of the this value.
15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
If min is not specified, this behaves as if min were specified with the value getMinutes( ).
If sec is not specified, this behaves as if sec were specified with the value getSeconds ( ).
If ms is not specified, this behaves as if ms were specified with the value getMilliseconds( ).
- Let t be the result of LocalTime(this time value).
- Call ToNumber( hour ).
- If min is not specified, compute MinFromTime( t ); otherwise, call ToNumber( min ).
- If sec is not specified, compute SecFromTime( t ); otherwise, call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
- Compute UTC(MakeDate(Day( t ), Result(6))).
- Set the [[Value]] property of the this value to TimeClip(Result(7)).
- Return the value of the [[Value]] property of the this value.
15.9.5.31 Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )
If min is not specified, this behaves as if min were specified with the value getUTCMinutes( ).
If sec is not specified, this behaves as if sec were specified with the value getUTCSeconds ( ).
If ms is not specified, this behaves as if ms were specified with the value getUTCMilliseconds( ).
- Let t be this time value.
- Call ToNumber( hour ).
- If min is not specified, compute MinFromTime( t ); otherwise, call ToNumber( min ).
- If sec is not specified, compute SecFromTime( t ); otherwise, call ToNumber( sec ).
- If ms is not specified, compute msFromTime( t ); otherwise, call ToNumber( ms ).
- Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
- Compute MakeDate(Day( t ), Result(6)).
- Set the [[Value]] property of the this value to TimeClip(Result(7)).
- Return the value of the [[Value]] property of the this value.
15.9.5.32 Date.prototype.setDate(date)
- Let t be the result of LocalTime(this time value).
- Call ToNumber( date ).
- Compute MakeDay(YearFromTime( t ), MonthFromTime( t ), Result(2)).
- Compute UTC(MakeDate(Result(3), TimeWithinDay( t ))).
- Set the [[Value]] property of the this value to TimeClip(Result(4)).
- Return the value of the [[Value]] property of the this value.
15.9.5.33 Date.prototype.setUTCDate(date)
- Let t be this time value.
- Call ToNumber( date ).
- Compute MakeDay(YearFromTime( t ), MonthFromTime( t ), Result(2)).
- Compute MakeDate(Result(3), TimeWithinDay( t )).
- Set the [[Value]] property of the this value to TimeClip(Result(4)).
6. Return the value of the [[Value]] property of the this value.
15.9.5.34 Date.prototype.setMonth(mon [, date ] )
If date is not specified, this behaves as if date were specified with the value getDate( ).
- Let t be the result of LocalTime(this time value).
- Call ToNumber( date ).
- If date is not specified, compute DateFromTime( t ); otherwise, call ToNumber( date ).
- Compute MakeDay(YearFromTime( t ), Result(2), Result(3)).
- Compute UTC(MakeDate(Result(4), TimeWithinDay( t ))).
- Set the [[Value]] property of the this value to TimeClip(Result(5)).
- Return the value of the [[Value]] property of the this value.
15.9.5.35 Date.prototype.setUTCMonth(mon [, date ] )
If date is not specified, this behaves as if date were specified with the value getUTCDate( ).
- Let t be this time value.
- Call ToNumber( date ).
- If date is not specified, compute DateFromTime( t ); otherwise, call ToNumber( date ).
- Compute MakeDay(YearFromTime( t ), Result(2), Result(3)).
- Compute MakeDate(Result(4), TimeWithinDay( t )).
- Set the [[Value]] property of the this value to TimeClip(Result(5)).
- Return the value of the [[Value]] property of the this value.
15.9.5.36 Date.prototype.setFullYear(year [, mon [, date ]] )
If mon is not specified, this behaves as if mon were specified with the value getMonth( ).
If date is not specified, this behaves as if date were specified with the value getDate( ).
- Let t be the result of LocalTime(this time value); but if this time value is NaN , let t be +0 .
- Call ToNumber( year ).
- If mon is not specified, compute MonthFromTime( t ); otherwise, call ToNumber( mon ).
- If date is not specified, compute DateFromTime( t ); otherwise, call ToNumber( date ).
- Compute MakeDay(Result(2), Result(3), Result(4)).
- Compute UTC(MakeDate(Result(5), TimeWithinDay( t ))).
- Set the [[Value]] property of the this value to TimeClip(Result(6)).
- Return the value of the [[Value]] property of the this value.
15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
If mon is not specified, this behaves as if mon were specified with the value getUTCMonth( ).
If date is not specified, this behaves as if date were specified with the value getUTCDate( ).
- Let t be this time value; but if this time value is NaN , let t be +0 .
- Call ToNumber( year ).
- If mon is not specified, compute MonthFromTime( t ); otherwise, call ToNumber( mon ).
- If date is not specified, compute DateFromTime( t ); otherwise, call ToNumber( date ).
- Compute MakeDay(Result(2), Result(3), Result(4)).
- Compute MakeDate(Result(5), TimeWithinDay( t )).
- Set the [[Value]] property of the this value to TimeClip(Result(6)).
- Return the value of the [[Value]] property of the this value.
15.9.5.38 Date.prototype.setYear(year)
This function is specified here for backwards compatibility only. The function setFullYear is much to be preferred for nearly all purposes, because it avoids the "year 2000 problem."
- Let t be the result of LocalTime(this time value); but if this time value is NaN , let t be +0 .
- Call ToNumber( year ).
- If Result(2) is NaN , set the [[Value]] property of the this value to NaN and return NaN .
- If Result(2) is not NaN and 0<=ToInteger(Result(2)) <=99 then Result(4) is ToInteger(Result(2)) + 1900. Otherwise Result(4) is Result(2).
- Compute MakeDay(Result(4), MonthFromTime( t ), DateFromTime( t )).
- Compute UTC(MakeDate(Result(5), TimeWithinDay( t ))).
- Set the [[Value]] property of the this value to TimeClip(Result(6)).
- Return the value of the [[Value]] property of the this value.
15.9.5.39 Date.prototype.toLocaleString()
This function returns a string value. The contents of the string are implementation dependent, but are intended to represent the Date in a convenient, human-readable form appropriate to the geographic or cultural locale
15.9.5.40 Date.prototype.toUTCString()
This function returns a string value. The contents of the string are implementation dependent, but are intended to represent the Date in a convenient, human-readable form in UTC.
15.9.5.41 Date.prototype.toGMTString()
The function object that is the initial value of Date.prototype.toGMTString is the same function object that is the initial value of Date.prototype.toUTCString . The toGMTString property is provided principally for compatibility with old code. It is recommended that the toUTCString property be used in new ECMAScript code.
15.9.6 Properties of Date Instances
Date instances have no special properties beyond those inherited from the Date prototype object.