-1

This question might sound silly but it really bugs me and I could not find any relevant answers. Is there any way to initialise a javascript variable of date type other than using the new Date() ?. I have the doubt which is similar to this SO question. I need to know if there are any shorter representations.

Krishna Prashatt
  • 631
  • 9
  • 18

1 Answers1

1

From the MDN Web Docs:

JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.

Link

So no, there is no other way. If you don't like it that way, you can take a look at date libraries like momentjs

Decay42
  • 802
  • 1
  • 9
  • 20