Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In javascript, the typical way to new up an object is by doing it like this: new Date(). But you can also do this: new (Date). What is the difference and advantages of doing it the latter way?

like image 565
Andrew Young Avatar asked Nov 23 '11 00:11

Andrew Young


People also ask

Is new date () the same as new date date NOW ())?

new Date() - creates a Date object representing the current date/time. Date. now() - returns the number of milliseconds since midnight 01 January, 1970 UTC.

What does new date () mean?

new Date() : Creates a date object set to the current date and time.

What is new date () in JavaScript?

The new Date() Constructor In JavaScript, date objects are created with new Date() . new Date() returns a date object with the current date and time.

What does date now () return?

The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.


1 Answers

There is no difference.

The new operator takes a function reference.
Like any other operator, the operand can have parentheses.

The () after a new expression with no arguments are optional.

However, if you have more a complicated expression inside the parentheses, they can change precedence ordering, such as in this answer.

like image 135
SLaks Avatar answered Sep 21 '22 01:09

SLaks