Date.now() — JS Technical Interview Questions & Answers

Returns the current timestamp in milliseconds.

Date.now()

  • Date.now() is a JS topic. In plain words you use it for a short Date.now example in a script in the browser. Don’t start with a slogan — start with that picture.
  • Smallest example: the smallest Date.now example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Date.now().
  • From the example next to this theory: Returns the current timestamp in milliseconds.
  • Trap: only saying “Date.now” with no example. Fix that before you talk about advanced JS.
  • Viva: what is Date.now()? Then show the smallest Date.now example you can type. Then name the trap.

Technical Interview Tip: What is Date.now()? Show this: the smallest Date.now example you can type. Trap: only saying “Date.now” with no example.

Code Examples for Date.now()

Date.now() — working example

// Topic: Date.now()
const nums = [1, 2, 3];
const doubled = nums.map((n) => n * 2);
console.log(doubled);
console.log(doubled.reduce((a, b) => a + b, 0));

Date.now(): map then reduce on [1, 2, 3]. Say both prints.

How to Explain Date.now() to an Interviewer

What is Date.now()?

Used for a short Date.now example a script in the browser Not just the heading

Give one small example of Date.now().

the smallest Date.now example you can type Returns the current timestamp in milliseconds

What mistake do beginners make with Date.now()?

only saying “Date.now” with no example Show the fix

Where do you use Date.now()?

a script in the browser a short Date.now example