What is the difference between new (Date) and new Date ()?

In javascript, a typical way to create a new object is as follows: new Date() . But you can also do this: new (Date) . What is the difference and advantages of this last way?

+7
source share
2 answers

There is no difference.

The new operator accepts a function reference.
Like any other operator, an operand can have parentheses.

() after the expression new without arguments is optional.

However, if you have a more complex expression inside parentheses, they can change the order of priorities, for example, in this answer .

+11
source

I believe that the latter method is identical to the former. I think this will be interpreted as new Date , since there is nothing to evaluate in parentheses. Note that new Date equivalent to new Date() .

0
source

All Articles