How to fix JavaScript Date().getTime() is not a function?

To fix JavaScript Date().getTime() is not a function, we need the new keyword before Date.

For instance, we write

const now = new Date().getTime();

to create a new date object with new Date().

And then we call getTime to get the current timestamp from the date object.