JavaScript Basic Date Handling (Date object) Quiz

JavaScript
0 Passed
0% acceptance

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.

50 Questions
~100 minutes
1

Question 1

What does new Date() with no arguments represent?

A
The current date and time in the local timezone
B
The epoch date (Jan 1 1970 UTC)
C
Undefined
D
Throws an error
2

Question 2

Which constructor call creates a Date from milliseconds since the epoch?

A
new Date(1660000000000)
B
new Date("1660000000000ms")
C
new Date().milliseconds
D
Date.parse(1660000000000)
3

Question 3

What is the result of Date.parse("2023-01-15T00:00:00Z")?

A
A millisecond timestamp for that UTC instant
B
A Date object
C
The local date string
D
NaN always
4

Question 4

How do you create a Date for March 5 2024 at noon local time?

A
new Date(2024, 2, 5, 12, 0, 0)
B
new Date(2024, 3, 5, 12, 0, 0)
C
new Date("2024,2,5,12")
D
Date.march(2024,5,12)
5

Question 5

Which method returns the number of milliseconds since Jan 1 1970 UTC for a Date instance?

A
date.getTime()
B
date.valueOfSeconds()
C
date.timestamp()
D
Date.epoch()
6

Question 6

What does Date.now() return?

A
Current timestamp in milliseconds as a number
B
A Date object
C
Seconds since epoch
D
The ISO string
7

Question 7

How do you create a Date from an ISO string?

A
new Date("2024-02-01T10:30:00Z")
B
Date.iso("2024-02-01")
C
Date.formatISO(...)
D
new DateISO(...)
8

Question 8

What is returned by new Date().toString()?

A
A human-readable local time string with timezone information
B
An ISO string
C
Milliseconds since epoch
D
UTC timestamp only
9

Question 9

Which Date constructor takes year, month, day, hours, minutes, seconds, milliseconds?

A
new Date(year, monthIndex, day, hours, minutes, seconds, ms)
B
new Date(day, month, year...)
C
Date.utc(...)
D
Date.parseComponents(...)
10

Question 10

Which Date creation method avoids implicit string parsing pitfalls?

A
Pass explicit numeric arguments or ISO strings to new Date
B
Pass custom formatted strings like "02/30/2024"
C
Use Date.parse on locale strings
D
Rely on Date("March 5th")
11

Question 11

Which method retrieves the month (0-11) from a Date?

A
date.getMonth()
B
date.getUTCMonthIndex()
C
date.month
D
date.getMonthIndex()
12

Question 12

How do you get the day of the week?

A
date.getDay()
B
date.day
C
date.dayOfWeek()
D
date.getWeekday()
13

Question 13

Which method returns the full year?

A
date.getFullYear()
B
date.getYear()
C
date.fullYear
D
date.year
14

Question 14

How do you retrieve the hours portion in local time?

A
date.getHours()
B
date.hours
C
date.getUTCHours()
D
date.getHourLocal()
15

Question 15

Which method changes the minutes field?

A
date.setMinutes(value)
B
date.minutes = value
C
date.setMinuteField(value)
D
Date.setMinutes(date, value)
16

Question 16

What does date.setDate(date.getDate() + 1) accomplish?

A
Adds one day while handling overflow to the next month if needed
B
Only changes the day field without adjusting the month
C
Throws an error if day exceeds month length
D
Always sets date to 1
17

Question 17

How do you extract milliseconds?

A
date.getMilliseconds()
B
date.milliseconds
C
date.getMS()
D
Date.milliseconds(date)
18

Question 18

What does date.toDateString() output?

A
A human-readable date portion without time
B
The ISO string
C
Milliseconds since epoch
D
UTC timestamp
19

Question 19

Which method returns the timezone offset in minutes from UTC?

A
date.getTimezoneOffset()
B
date.timezone
C
date.getUTCOffset()
D
date.offsetMinutes
20

Question 20

How do you produce a locale-aware short date string?

A
date.toLocaleDateString()
B
date.toISODateString()
C
Date.localeDate(date)
D
date.localeString("short")
21

Question 21

What does this code log?

javascript
const ts = Date.now()
console.log(typeof ts)
A
"number"
B
"string"
C
"object"
D
"date"
22

Question 22

What is the output?

javascript
const date = new Date('2024-01-01T00:00:00Z')
console.log(date.toISOString())
A
2024-01-01T00:00:00.000Z
B
A locale string
C
Milliseconds since epoch
D
Throws TypeError
23

Question 23

How do you add 2 days to a Date?

javascript
const date = new Date('2024-03-10T12:00:00Z')
date.setDate(date.getDate() + 2)
A
date now represents March 12 2024
B
date remains unchanged
C
A new Date is returned
D
Throws due to DST
24

Question 24

What does Date.parse("invalid") return?

javascript
console.log(Date.parse('invalid'))
A
NaN
B
0
C
Throws SyntaxError
D
A Date object
25

Question 25

How do you get the difference in milliseconds between two dates?

javascript
const start = new Date('2024-01-01')
const end = new Date('2024-01-10')
const diff = end - start
A
diff equals milliseconds between dates because Date objects coerce to timestamps
B
diff is NaN
C
diff is a Date object
D
diff is a string
26

Question 26

What does date.getUTCFullYear() return compared to getFullYear()?

javascript
const date = new Date('2023-12-31T23:00:00-02:00')
console.log(date.getFullYear(), date.getUTCFullYear())
A
Local year may differ from UTC year near midnight boundaries
B
Both always match
C
UTC method throws
D
getUTCFullYear returns timezone offset
27

Question 27

Which snippet clones a Date?

javascript
const copy = new Date(original.getTime())
A
Creates an independent Date with the same timestamp
B
Creates a reference to the same object
C
Throws because Date cannot be cloned
D
copy is undefined
28

Question 28

What is logged here?

javascript
const date = new Date('2024-01-01T00:00:00Z')
console.log(date.toUTCString())
A
A human-readable UTC date string (e.g., Mon, 01 Jan 2024 00:00:00 GMT)
B
Locale string
C
ISO string
D
Milliseconds
29

Question 29

What does date.toISOString().slice(0, 10) provide?

javascript
const date = new Date('2024-04-25T10:15:00Z')
console.log(date.toISOString().slice(0, 10))
A
The YYYY-MM-DD portion of the ISO string (2024-04-25)
B
The local date
C
Timezone offset
D
Milliseconds
30

Question 30

What happens when you pass a Date to JSON.stringify?

javascript
const obj = { createdAt: new Date('2024-02-01T12:00:00Z') }
console.log(JSON.stringify(obj))
A
Dates are serialized as ISO strings by default
B
Dates are removed
C
Dates become timestamps
D
Serialization throws
31

Question 31

How do you convert a timestamp to seconds?

javascript
const seconds = Math.floor(Date.now() / 1000)
A
Divide milliseconds by 1000 and floor to get integer seconds
B
Use Date.seconds()
C
Call getSeconds on Date.now
D
Use date.toSeconds()
32

Question 32

What does Date.UTC(y, m, d, h, min, s) return?

javascript
const ts = Date.UTC(2024, 0, 1, 0, 0, 0)
console.log(ts)
A
Milliseconds timestamp representing the UTC date
B
A Date object
C
A locale string
D
NaN
33

Question 33

What is the result?

javascript
const date = new Date('2024-03-10T02:30:00')
date.setHours(date.getHours() + 1)
console.log(date.toString())
A
Adds an hour even across DST boundaries; local time adjusts accordingly
B
Throws due to DST
C
SetHours is unavailable
D
Time stays identical
34

Question 34

How do you format a Date with Intl.DateTimeFormat?

javascript
const formatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeStyle: 'short' })
console.log(formatter.format(new Date('2024-05-01T15:45:00Z')))
A
Outputs a localized string such as "May 1, 2024, 11:45 AM" depending on timezone
B
Always outputs ISO string
C
Throws due to options
D
Returns milliseconds
35

Question 35

What does this comparison log?

javascript
const a = new Date('2024-01-01T00:00:00Z')
const b = new Date('2024-01-01T12:00:00Z')
console.log(a < b)
A
true because date objects compare by numeric timestamp
B
false because objects cannot be compared
C
Throws TypeError
D
Compares string representations
36

Question 36

What does date.toLocaleString("en-GB", { timeZone: "UTC" }) do?

A
Formats the date/time in the specified locale while forcing UTC timezone
B
Converts the Date object to UTC permanently
C
Throws if timezone is provided
D
Ignores the locale
37

Question 37

Which method returns the UTC date (day of month)?

A
date.getUTCDate()
B
date.getUTCDayOfMonth()
C
date.getUTCDay()
D
date.utcDate
38

Question 38

What is a common pitfall of Date parsing in JavaScript?

A
Locale-dependent strings may parse differently across browsers
B
ISO strings are unsupported
C
Date.parse always throws
D
Date cannot parse numbers
39

Question 39

Why should you avoid mutating Date objects shared across code?

A
Dates are mutable; accidental set operations can ripple through shared references
B
Dates throw on mutation
C
Dates auto-clone when passed
D
Dates cannot be mutated at all
40

Question 40

What is a safe way to compare only the date portion of two Date objects?

A
Compare date.toDateString() values or zero out time components before comparing timestamps
B
Compare getTime directly without adjustments
C
Compare getMilliseconds only
D
Use Date.equals method
41

Question 41

What challenge does daylight saving time introduce?

A
Adding hours across DST boundaries can skip or repeat local times
B
UTC methods stop working
C
Date.now breaks
D
ISO strings become invalid
42

Question 42

What is returned by new Date("2024-01-01").getTimezoneOffset()?

A
Minutes difference between local timezone and UTC on that date
B
Always 0
C
Hours difference as a float
D
Milliseconds difference
43

Question 43

Why can new Date("02/03/2024") be ambiguous?

A
Different locales interpret month/day order differently
B
Date cannot parse numeric strings
C
ISO requires hyphens
D
JavaScript disallows slashes
44

Question 44

How do you convert a Date to a timestamp in seconds?

A
Math.floor(date.getTime() / 1000)
B
date.toSeconds()
C
date.seconds
D
Date.seconds(date)
45

Question 45

Which method yields a JSON-friendly string?

A
date.toJSON()
B
date.toLocaleString()
C
date.customFormat()
D
date.stringify()
46

Question 46

What does Date.prototype.valueOf return?

A
The numeric timestamp (same as getTime)
B
Locale string
C
Date object
D
UTC string
47

Question 47

Why is storing Date objects in JSON problematic?

A
Dates serialize to strings; you must parse them back when reading
B
JSON cannot store strings
C
JSON automatically stores timestamps
D
Dates mutate JSON
48

Question 48

Which practice avoids implicit timezone conversions when comparing two dates?

A
Compare their timestamps via getTime or valueOf
B
Compare toLocaleString outputs
C
Compare Date.toString values
D
Compare month names
49

Question 49

How do you get a UTC ISO string without milliseconds?

A
date.toISOString().replace(/\.\d{3}Z$/, "Z")
B
date.toUTCString()
C
date.toJSONNoMs()
D
date.toISOString().milliseconds(false)
50

Question 50

What is a best practice when performing Date arithmetic?

A
Work with timestamps (milliseconds) and create new Date objects as needed
B
Mutate shared Date instances everywhere
C
Rely on implicit string parsing for math
D
Avoid UTC methods entirely

QUIZZES IN JavaScript