Dr said:
While it may be time-saving for you, it would be polite towards the author
of the article, the potential reader, and prudent in general (e.g. in order
not to demonstrate usually inappropriate practice to the uninitiated by a
regular) if you posted a followup to the article you are referring to, in
which you quoted the relevant parts you are referring to, instead.
parseInt(S) for S being "08" or "09" gives zero (the standard
reluctantly allows that); so, in this context, if parseInt
is used then it does need ', 10'.
But without parseInt, "08" and "09" are taken as eight and nine;
although "077" is sixty-three, "078" is seventy-eight - at least,
wherever I've tried it. That seems compatible with ISO/IEC 16262 B.1.
I don't know what ISO/IEC 16262 B.1 says (I won't spend the money required
in order to read it), but if that international standard says the same as
section B.1 of the (freely available) European standard ECMA-262-3 (which
was later approved as ISO/IEC 16262), then the observed behavior would not
be compatible with the compatibility grammar defined there:
| B.1 Additional Syntax
|
| Past editions of ECMAScript have included additional syntax and semantics
| for specifying octal literals and octal escape sequences. These have been
| removed from this edition of ECMAScript. This non-normative annex presents
| uniform syntax and semantics for octal literals and octal escape sequences
| for compatibility with some older ECMAScript programs.
|
| B.1.1 Numeric Literals
|
| The syntax and semantics of section 7.8.3 can be extended as follows:
|
| *Syntax*
|
| NumericLiteral ::
| DecimalLiteral
| HexIntegerLiteral
| OctalIntegerLiteral
|
| OctalIntegerLiteral ::
| 0 OctalDigit
| OctalIntegerLiteral OctalDigit
|
| *Semantics*
|
| • The MV of NumericLiteral :: OctalIntegerLiteral is the MV of
| OctalIntegerLiteral.
| • The MV of OctalDigit :: 0 is 0.
| • The MV of OctalDigit :: 1 is 1.
| • The MV of OctalDigit :: 2 is 2.
| • The MV of OctalDigit :: 3 is 3.
| • The MV of OctalDigit :: 4 is 4.
| • The MV of OctalDigit :: 5 is 5.
| • The MV of OctalDigit :: 6 is 6.
| • The MV of OctalDigit :: 7 is 7.
| • The MV of OctalIntegerLiteral :: 0 OctalDigit is the MV of OctalDigit.
| • The MV of OctalIntegerLiteral :: OctalIntegerLiteral OctalDigit is
| (the MV of OctalIntegerLiteral times 8) plus the MV of OctalDigit.
Whereas the MV is defined as follows:
| 7.8.3.
|
| A numeric literal stands for a value of the Number type. This value is
| determined in two steps: first, a mathematical value (MV) is derived from
| the literal; [...]
Without a closer look, one could then easily conclude that 08 would be
parsed as a DecimalLiteral and 077 be parsed as an OctalIntegerLiteral.
However, that possibility is explicitly excluded by the grammar:
| 7.8.3 Numeric Literals
|
| Syntax
|
| DecimalLiteral ::
| DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt
| . DecimalDigits ExponentPartopt
| DecimalIntegerLiteral ExponentPartopt
|
| DecimalIntegerLiteral ::
| 0
| NonZeroDigit DecimalDigitsopt
|
| DecimalDigits ::
| DecimalDigit
| DecimalDigits DecimalDigit
|
| DecimalDigit :: one of
| 0 1 2 3 4 5 6 7 8 9
|
| NonZeroDigit :: one of
| 1 2 3 4 5 6 7 8 9
So if e.g. +"08" (or 08) resulted in 8, but +"077" (or 077) resulted in 63,
then this behavior could only be one backed up by
| 2 Conformance
|
| [...] A conforming implementation of ECMAScript is permitted to support
| program and regular expression syntax not described in this specification.
Which would be precisely the reason why I would use parseInt(..., 10) here.
Incidentally, Firefox 2.0.0.6 gives
| Warning: 08 is not a legal ECMA-262 octal constant
Javascript lacks specific syntax for creating a Date Object of a given
Ordinal Date;
Define "Ordinal Date". If you mean something like the number of
milliseconds since the beginning of the UNIX era, then
new Date(timestamp)
where timestamp is that number, works in JavaScript (and JScript, Opera
ECMAScript and KJS), and is specified in ES3:
| 15.9.3.2 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 (section 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:
|
| 1. Call ToPrimitive(value).
| 2. If Type(Result(1)) is String, then go to step 5.
| 3. Let V be ToNumber(Result(1)).
| 4. Set the [[Value]] property of the newly constructed object
| to TimeClip(V) and return.
| 5. [...]
Whereas the [[Value]] property of a Date object is defined implicitly as
follows:
| 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 –9,007,199,254,740,991 to 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.
|
| The exact moment of midnight at the beginning of 01 January, 1970 UTC is
| represented by the value +0.
PointedEars