JavaScript Basic Date Handling (Date object) Quiz
Answer 50 questions on JavaScript Date basics: creating instances, timestamps, extracting components, setting values, parsing strings, basic formatting, Date.now, arithmetic, time zones, UTC helpers, comparisons, ISO conversion, and common pitfalls.
Question 1
What does new Date() with no arguments represent?
Question 2
Which constructor call creates a Date from milliseconds since the epoch?
Question 3
What is the result of Date.parse("2023-01-15T00:00:00Z")?
Question 4
How do you create a Date for March 5 2024 at noon local time?
Question 5
Which method returns the number of milliseconds since Jan 1 1970 UTC for a Date instance?
Question 6
What does Date.now() return?
Question 7
How do you create a Date from an ISO string?
Question 8
What is returned by new Date().toString()?
Question 9
Which Date constructor takes year, month, day, hours, minutes, seconds, milliseconds?
Question 10
Which Date creation method avoids implicit string parsing pitfalls?
Question 11
Which method retrieves the month (0-11) from a Date?
Question 12
How do you get the day of the week?
Question 13
Which method returns the full year?
Question 14
How do you retrieve the hours portion in local time?
Question 15
Which method changes the minutes field?
Question 16
What does date.setDate(date.getDate() + 1) accomplish?
Question 17
How do you extract milliseconds?
Question 18
What does date.toDateString() output?
Question 19
Which method returns the timezone offset in minutes from UTC?
Question 20
How do you produce a locale-aware short date string?
Question 21
What does this code log?
const ts = Date.now()
console.log(typeof ts)Question 22
What is the output?
const date = new Date('2024-01-01T00:00:00Z')
console.log(date.toISOString())Question 23
How do you add 2 days to a Date?
const date = new Date('2024-03-10T12:00:00Z')
date.setDate(date.getDate() + 2)Question 24
What does Date.parse("invalid") return?
console.log(Date.parse('invalid'))Question 25
How do you get the difference in milliseconds between two dates?
const start = new Date('2024-01-01')
const end = new Date('2024-01-10')
const diff = end - startQuestion 26
What does date.getUTCFullYear() return compared to getFullYear()?
const date = new Date('2023-12-31T23:00:00-02:00')
console.log(date.getFullYear(), date.getUTCFullYear())Question 27
Which snippet clones a Date?
const copy = new Date(original.getTime())Question 28
What is logged here?
const date = new Date('2024-01-01T00:00:00Z')
console.log(date.toUTCString())Question 29
What does date.toISOString().slice(0, 10) provide?
const date = new Date('2024-04-25T10:15:00Z')
console.log(date.toISOString().slice(0, 10))Question 30
What happens when you pass a Date to JSON.stringify?
const obj = { createdAt: new Date('2024-02-01T12:00:00Z') }
console.log(JSON.stringify(obj))Question 31
How do you convert a timestamp to seconds?
const seconds = Math.floor(Date.now() / 1000)Question 32
What does Date.UTC(y, m, d, h, min, s) return?
const ts = Date.UTC(2024, 0, 1, 0, 0, 0)
console.log(ts)Question 33
What is the result?
const date = new Date('2024-03-10T02:30:00')
date.setHours(date.getHours() + 1)
console.log(date.toString())Question 34
How do you format a Date with Intl.DateTimeFormat?
const formatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' })
console.log(formatter.format(new Date('2024-05-01T15:45:00Z')))Question 35
What does this comparison log?
const a = new Date('2024-01-01T00:00:00Z')
const b = new Date('2024-01-01T12:00:00Z')
console.log(a < b)Question 36
What does date.toLocaleString("en-GB", { timeZone: "UTC" }) do?
Question 37
Which method returns the UTC date (day of month)?
Question 38
What is a common pitfall of Date parsing in JavaScript?
Question 39
Why should you avoid mutating Date objects shared across code?
Question 40
What is a safe way to compare only the date portion of two Date objects?
Question 41
What challenge does daylight saving time introduce?
Question 42
What is returned by new Date("2024-01-01").getTimezoneOffset()?
Question 43
Why can new Date("02/03/2024") be ambiguous?
Question 44
How do you convert a Date to a timestamp in seconds?
Question 45
Which method yields a JSON-friendly string?
Question 46
What does Date.prototype.valueOf return?
Question 47
Why is storing Date objects in JSON problematic?
Question 48
Which practice avoids implicit timezone conversions when comparing two dates?
Question 49
How do you get a UTC ISO string without milliseconds?
Question 50
What is a best practice when performing Date arithmetic?
