Date() constructor definition

I tried to understand the semantics of Date() constructors with arguments, as defined in sections 20.3.2.1 and 20.3.2.2 of ECMA-262, 10th edition. The step 3 in both sections says:

  1. If NewTarget is undefined, then
    a. Let now be the Number that is the time value (UTC) identifying the current time.
    b. Return ToDateString(now).

If I understand correctly, "NewTarget is undefined" means that the constructor is being called as a function. This step seems to say that if Date() with argument(s) is called as a function, the argument(s) are ignored and current time is returned. Or, just maybe, it is an unedited copy-paste from the Date() with no arguments?

I am new to reading the ECMAScript specification, which is not particularly fool-friendly, so I thought I will ask a question before formally reporting an issue: What am I missing?

https://tc39.es/ecma262/#sec-date-year-month-date-hours-minutes-seconds-ms is for when Date is called with 2+ arguments, https://tc39.es/ecma262/#sec-date-value is for when it's called with 1, and https://tc39.es/ecma262/#sec-date-constructor-date is for when it's called with zero.

More precisely: arguments are ignored and a string representation of the current date & time is returned.

Thanks! So is ignoring parameters the intended behavior? It seems a bit weird to me.

It's been that way since the first edition of the ECMAScript spec:

When Date is called as a function rather than as a constructor, it returns a string representing the current time(UTC). [...] The arguments are accepted but are completely ignored.

Again, it doesn’t ignore parameters; the Date function is overloaded in the spec, so the zero-parameter one only applies to a zero argument invocation.

1 Like

But this question isn't about zero-argument invocations, it's about invocations "with arguments". So the first or second overloads are relevant, and both of them ignore parameters when you invoke Date "as a function".

1 Like

Thanks a lot! This design is highly confusing. But OK, at least I have understood the specification correctly :)