0

On Node.js, when I execute the following two statements:

console.log(new Date);
console.log(new Date());

Both produce the same result.

What is the difference?

I have been told to use new Date(), although no reason was given.

Don't Mind Me
  • 179
  • 1
  • 1
  • 8

1 Answers1

1

from the syntax of new operator:

new constructor[([arguments])]

the parentheses is optional, so both expressions are valid.

console.log(new Date);
console.log(new Date());
Val
  • 21,938
  • 10
  • 68
  • 86
  • 1
    Note that MDN is not an authority, ECMA-262 is ([*§12.3.3*](http://ecma-international.org/ecma-262/8.0/#sec-new-operator) applies). That symbology is an invention of the article's author, it is not used in the language specification. – RobG Jul 31 '17 at 03:35