JavaScript Date & Math Objects

📆 Date Object

The Date object in JavaScript is used to work with **dates and times**. It can be used to get the current date, time, calculate differences, format time, etc.

Creating Date Objects:

const now = new Date();
const specific = new Date('2025-08-05T10:30:00');

Useful Date Methods:

Popular Use Cases:

Example:

const now = new Date();
console.log(now.toLocaleDateString()); // 8/5/2025
console.log(now.getFullYear()); // 2025

📚 Reference: MDN Web Docs - Date

🧮 Math Object

The Math object provides basic mathematics functions and constants. It's used for rounding, generating random numbers, getting min/max, etc.

Popular Math Methods:

Common Use Cases:

Example:

const otp = Math.floor(Math.random() * 9000 + 1000); // 4-digit OTP
console.log(otp); // e.g., 4821

console.log(Math.max(10, 2, 99)); // 99

📚 Reference: MDN Web Docs - Math