const now = new Date();
console.log(now.getTime()); // e.g. 1770512400000
Topics
37
ArrayBuffer, TypedArrays & Binary Data
Arrays & Array Methods
Async Iterators & Streams
Browser Storage & Web APIs
Classes & Class Syntax
Date, Time & Internationalization (Intl API)
Debugging, Testing & Tooling
Design Patterns in JavaScript
Destructuring, Spread & Rest
DOM & Events
Error Handling
ES Modules
Event Loop & Concurrency
Functional Programming
Iterators & Generators
JSON & Data Serialization
Map, Set, WeakMap & WeakSet
Memory Management & Garbage Collection
Networking: Fetch, XHR, WebSockets & CORS
Numbers, Math & BigInt
Objects, Property Descriptors & Immutability
Optional Chaining & Nullish Coalescing
Package Management, Bundlers & Transpilation (npm, Webpack/Vite, Babel)
Performance Optimization: Debouncing, Throttling & Memoization
Promises & async/await
Prototypes & Inheritance
Proxy & Reflect
Regular Expressions
Scope, Hoisting & Closures
Security: XSS, CSRF & Content Security Policy
Service Workers & Progressive Web Apps
Strings & Template Literals
Symbols & Well-Known Symbols
this & Binding
Types & Coercion
Web Components & Custom Elements
Web Workers & Multithreading
Date, Time & Internationalization (Intl API)
10 questions found
new Date() with no arguments creates a Date object set to the current date and time, based on the system clock, represented internally as milliseconds since the Unix epoch (Jan 1, 1970 UTC).
Real-world example
Timestamping when a user submits a form, for auditing or sorting purposes.
Numbers
Math & BigInt
Date.parse() (and new Date(string)) behavior for non-ISO formats is implementation-defined, so the same string can parse differently across browsers. Only the ISO 8601 format (e.g. '2026-08-08') is guaranteed to parse consistently.
new Date('2026-08-08'); // reliable, ISO format
new Date('08/08/2026'); // ambiguous across locales/engines
Real-world example
A bug where a date string parsed fine in Chrome but produced Invalid Date in Safari.
Error Handling
Intl.DateTimeFormat lets you format dates according to locale conventions and customizable options (weekday, month style, etc.), without needing an external date library for basic formatting.
const formatter = new Intl.DateTimeFormat('en-GB', { dateStyle: 'long' });
console.log(formatter.format(new Date())); // '8 August 2026'
Real-world example
Displaying order dates in the format users in a specific country expect (DD/MM/YYYY vs MM/DD/YYYY).
Design Patterns in JavaScript
Subtracting two Date objects (or calling getTime() on each) yields the difference in milliseconds; divide by the number of milliseconds in a day (1000*60*60*24) to get whole days.
const start = new Date('2026-08-01');
const end = new Date('2026-08-08');
const days = (end - start) / (1000*60*60*24); // 7
Real-world example
Calculating how many days remain until a subscription renews.
Numbers
Math & BigInt
Intl.NumberFormat handles locale-aware digit grouping, decimal separators, and currency symbols automatically, avoiding manual and error-prone string manipulation.
const price = new Intl.NumberFormat('de-DE', {
style: 'currency', currency: 'EUR'
}).format(1234.5);
console.log(price); // '1.234,50 €'
Real-world example
Displaying product prices correctly formatted for a user's detected region.
Types & Coercion
The built-in Date object always represents a single instant in time and only exposes it in either UTC or the *local system's* time zone — there's no built-in way to reliably format a date in an arbitrary, different time zone without extra options or a library.
// Formatting in a specific, non-local zone requires Intl:
new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York', timeStyle: 'short'
}).format(new Date());
Real-world example
Showing a meeting time correctly in both the organizer's and an attendee's time zones.
Error Handling
Default string comparison (< and >) uses UTF-16 code point order, which doesn't match human-expected alphabetical order for many languages (accents, special characters). Intl.Collator provides locale-aware, linguistically correct sorting.
const collator = new Intl.Collator('sv');
['ö', 'z', 'a'].sort(collator.compare); // locale-correct Swedish order
Real-world example
Sorting a list of customer names correctly for users in different countries, respecting local alphabetization rules.
Arrays & Array Methods
Temporal is a modern proposal/API for date and time handling designed to replace the flawed, mutable Date object with immutable, explicit types (PlainDate, ZonedDateTime, Duration, etc.) that handle time zones and calendars correctly by design.
// Temporal (where available):
const date = Temporal.PlainDate.from('2026-08-08');
const later = date.add({ days: 7 });
console.log(later.toString()); // '2026-08-15'
Real-world example
Building a scheduling app where date math needs to be reliably correct across time zones and calendar edge cases.
Design Patterns in JavaScript
Intl.RelativeTimeFormat generates locale-correct relative phrases from a numeric offset and unit, without manually building strings like 'X days ago'.
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-3, 'day')); // '3 days ago'
console.log(rtf.format(1, 'day')); // 'tomorrow'
Real-world example
Showing 'Posted 2 hours ago' style timestamps in a social feed or comment section.
Numbers
Math & BigInt
The Date constructor's month argument is zero-indexed (0 = January, 11 = December) for historical reasons, so month 7 means the 8th month, August — a very common source of off-by-one date bugs.
const d = new Date(2026, 7, 8);
console.log(d.getMonth()); // 7
console.log(d.toDateString()); // 'Sat Aug 08 2026'
Real-world example
A recurring bug class where developers pass the human month number directly and get the wrong month.
Error Handling