This quiz is completed
What is the result of new Date(0).toUTCString()?
Thu Jan 01 1970 01:00:00 GMT+0100 (Local Time)Thu, 01 Jan 1970 00:00:00 GMTWed Dec 31 1969 19:00:00 GMT-0500 (EST)Invalid DateWhat does new Date(2023, 0, 1).getMonth() return?
0
1
2
12
In the call new Date(year, month, day, hours, minutes, seconds, milliseconds), what happens if any parameter exceeds its logical range (e.g., new Date(2023, 12, 40))?
It throws a
RangeError.It returns
"Invalid Date".The date auto-corrects (e.g., month 13 becomes year 2024, month 1).
It returns
null.What is the output of new Date('2023-02-29')?
A valid Date object for February 29, 2023.
A Date object representing March 1, 2023.
Invalid Date.A Date object for February 28, 2023.
What is the value of d after running let d = new Date(); d.setDate(d.getDate() + 1);?
The date object
d represents the same day it was created.The date object
d represents exactly 24 hours in the future.The date object
d represents tomorrow's date.The date object
d represents the first day of the next month.How does JavaScript interpret the date string '05 October 2011 14:48 UTC'?
It is parsed as local time.
It is parsed as UTC.
It throws a SyntaxError.
Parsing behavior is implementation-dependent and unreliable.
What is the result of Date.parse('foo')?
0nullundefinedNaNWhat is the output of new Date(NaN).toString()?
"NaN""Invalid Date""undefined"It throws an error.
Given let d = new Date('2023-10-05T10:00:00'); in a browser set to US Eastern Time (EDT/EST), what will d.getHours() return?
10
6 (if in EDT, which is UTC-4)
5 (if in EST, which is UTC-5)
It depends on the current daylight saving time at the time the code is run.
What is the key difference between getMonth() and getUTCMonth() for a date created with new Date()?
getMonth() returns a 1-based index, getUTCMonth() returns 0-based.getMonth() uses the local timezone, getUTCMonth() uses UTC.getMonth() is a string, getUTCMonth() is a number.There is no difference; they are aliases.
What is logged by console.log(new Date(2023, 9, 5) === new Date(2023, 9, 5))?
truefalsenullundefinedWhat does new Date().getTime() return?
The current year.
The number of milliseconds since January 1, 1970, 00:00:00 UTC.
The number of seconds since January 1, 1970, 00:00:00 UTC.
The current time in a human-readable string.
What is a critical issue with using new Date(string) for user-provided date strings?
It only accepts ISO 8601 format.
Parsing is implementation-dependent and can produce different results in different browsers/environments.
It is significantly slower than using number arguments.
It automatically converts the string to UTC.
What is the value of date after let date = new Date(2023, 5, 31); date.setMonth(1);? (February in a non-leap year)
February 28, 2023
March 3, 2023
March 2, 2023
March 1, 2023
What is the result of new Date('2023-10-05') compared to new Date(2023, 9, 5)?
They represent the exact same moment in time.
The first is interpreted as UTC midnight, the second as local time midnight.
The first is interpreted as local time midnight, the second as UTC midnight.
The first is invalid, the second is valid.
How can you create a new Date object that is a copy of an existing one?
let copy = originalDate;let copy = new Date(originalDate.getTime());let copy = originalDate.clone();let copy = Date.copy(originalDate);What is the output of new Date().getYear()? (Not getFullYear())
The current 4-digit year (e.g., 2023).
The number of years since 1900 (e.g., 123).
The number of years since 2000 (e.g., 23).
This method is deprecated and should not be used.
What is the value of new Date(2023, 0).getDay()? (January 1, 2023, was a Sunday)
0
1
6
31
What is the most reliable way to get the number of days in a given month and year?
new Date(year, month+1, 0).getDate()new Date(year, month, 31).getDate()Use a lookup array.
new Date(year, month).getDaysInMonth()What does Date.now() return?
A formatted string of the current date and time.
A Date object for the current moment.
The number of milliseconds since the epoch, similar to
new Date().getTime().The number of seconds since the epoch.
What is a potential "gotcha" when using toISOString()?
It outputs the date in the user's local timezone.
It always converts the date to UTC before outputting the string.
It cannot be used on dates before the year 1900.
It returns a human-readable string instead of an ISO string.
What is logged? let d = new Date('2023-01-01T00:00:00Z'); console.log(d.getMonth() + ',' + d.getUTCMonth()); (User in EST)
11,110,011,00,11What is the behavior of new Date(undefined)?
It creates a date for the current time.
It is equivalent to
new Date(NaN), creating an invalid date.It is equivalent to
new Date(null).It throws a
TypeError.What is the result of new Date('0001-01-01').getFullYear()?
11901-1It returns
NaN because the year is too small.How does Date.UTC(2023, 9, 5) differ from new Date(2023, 9, 5)?
Date.UTC returns a timestamp number, while new Date creates a Date object. Date.UTC also interprets the arguments as UTC, not local time.Date.UTC creates a Date object in UTC, while new Date creates one in local time.They are functionally identical.
Date.UTC is deprecated.What is the value of end? let start = new Date(); /* some synchronous operation */ let end = new Date() - start;
A Date object.
The number of milliseconds the operation took.
NaN.undefined.What is the output of new Date('2023-10-05').toDateString() in a browser in GMT?
Thu Oct 05 2023Thu Oct 05 2023 GMT+0000 (Greenwich Mean Time)2023-10-05T00:00:00.000Z10/5/2023What is a major reason for using a library like moment.js or date-fns over the native Date object?
The native Date object is much slower.
The native Date object lacks a comprehensive API for parsing, validating, manipulating, and formatting dates, and has well-known timezone pitfalls.
The native Date object cannot handle dates before the year 2000.
The native Date object is not a standard part of JavaScript.
What is the result of new Date(2023, 9, 5, 25, 0, 0).getDate()?
56Invalid Date4What is the primary purpose of the valueOf() method on a Date object?
To return a formatted date string.
To return the primitive value of the object (the timestamp), which allows dates to be compared with
< and >.To return the timezone offset.
To convert the date to a JSON string.