Skip to content

Files

Latest commit

 

History

History
20 lines (14 loc) · 424 Bytes

prefer-date-now.md

File metadata and controls

20 lines (14 loc) · 424 Bytes

Pattern: Timestamp creation via new Date()

Issue: -

Description

Using Date.now() is more concise and efficient than new Date().getTime() or new Date().valueOf() as it avoids creating unnecessary Date objects.

Examples

Example of incorrect code:

const ts = new Date().getTime();
const ts = new Date().valueOf();

Example of correct code:

const ts = Date.now();