Stop using Date in JavaScript for new projects The Date object is now officially legacy. TC39 is replacing it with the Temporal API. If you're still writing new Date() in 2026, you're shipping technical debt. Why Date is a problem: Mutable by default: Calling setDate changes the original object. That’s how you get surprise bugs in production. Months start at zero: January is 0. December is 11. Every dev has been burned by this at least once. Timezone chaos: new Date("2026-01-01") can give you Dec 31st at night depending on where your server runs. One object for everything: No way to represent just a date or just a time. It’s always a full datetime whether you want it or not. How Temporal fixes this: It’s immutable, so every operation returns a new value. Months start at 1 like normal humans expect. And you get specific types: PlainDate for dates only, PlainTime for time only, ZonedDateTime when you care about timezones, Duration for math. Instead of adding 86400000 milliseconds to add a day, you just write add one day. Way cleaner. What to do today: For new projects, use date-fns or Day.js until Temporal lands in browsers. If you want to be future-proof, try the @js-temporal/polyfill now. Temporal is Stage 3 and landing soon. Don’t let legacy APIs hold your codebase back. What are you using for dates in 2026? Let me know below 👇 #JavaScript #WebDev #Temporal #CleanCode #Frontend #TypeScript
Migrate from Date to Temporal API in JavaScript
More Relevant Posts
-
I just published a new open-source library: input-mask. I built it because input masking on the frontend often feels more annoying than it should be, especially in simple projects, forms, landing pages, and workflows where you just want to configure the field and move on. The idea is straightforward: apply input masks using HTML attributes only, without needing to write JavaScript just to initialize everything. You add the library via CDN, use attributes like data-mask="pattern" or data-mask="currency" on the input, and it handles the rest. Under the hood it uses IMask, but the whole point was to hide that complexity and make the implementation much more accessible. The first public version already supports: • pattern • regex • number • currency • date Repo: https://lnkd.in/e6pkj7wB CDN: https://lnkd.in/ebc7fdr5 If anyone wants to try it, share feedback, or suggest improvements, I’d love to hear it. #javascript #frontend #webdev #opensource #forms #nocode
To view or add a comment, sign in
-
A promise is just an object with two properties. The word "promise" sounds abstract. The actual thing is surprisingly concrete. When fetch() runs, JavaScript immediately returns an object - before any data has come back. That object has two properties: - value (undefined for now) - onFulfillment (an array of functions to run when value arrives) That's it. A placeholder with a slot for data and a list of what to do when it shows up. When the browser finishes the network request, it fills in value and auto-triggers everything in onFulfillment - passing the value as the argument. You get something immediately so your code can keep moving, and you attach behavior to a future value. That's the whole mechanism behind async JavaScript. Next: .then() - what it's actually doing (hint: not what the name implies). #JavaScript #WebDevelopment #SoftwareEngineering #Frontend
To view or add a comment, sign in
-
Everything was working… until production said otherwise 😅 One of the trickiest bugs in JavaScript is when your code is technically correct… but finishes in the wrong order. Many developers think: “If I use async/await, I’m safe.” Sadly… no 😄 async/await makes code look clean. It does NOT control which request finishes first. That’s where race conditions begin. Simple example: User searches “React” → Request 1 starts Immediately searches “Node.js” → Request 2 starts If Request 1 finishes later, old data can replace the new result. Now your UI confidently shows… the wrong answer. Classic. Same thing happens in Node.js too: ✔ Multiple API calls updating the same data ✔ Parallel requests overwriting each other ✔ Background jobs fighting like siblings Everything runs. Everything breaks. How to avoid it: ✔ Cancel old requests ✔ Ignore stale responses ✔ Use request IDs ✔ Debounce fast actions ✔ Handle backend concurrency properly Big lesson: async/await is syntax. Correct execution order is architecture. Very different things. Good code is not just: “It runs on my machine.” Good code is: “It runs correctly in production.” 😄 Have you ever debugged a race condition bug that made you question your life choices? 👇 #JavaScript #NodeJS #AsyncAwait #RaceConditions #FrontendDevelopment #BackendDevelopment #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
-
-
𝗡𝗼𝗱𝗲.𝗷𝘀 𝟮𝟲 𝘀𝗵𝗶𝗽𝘀 𝘄𝗶𝘁𝗵 𝗧𝗲𝗺𝗽𝗼𝗿𝗮𝗹 𝗔𝗣𝗜 𝗲𝗻𝗮𝗯𝗹𝗲𝗱 𝗯𝘆 𝗱𝗲𝗳𝗮𝘂𝗹𝘁. Date has been JavaScript's most universally hated API for decades. Mutable, zero-indexed months, no timezone support, inconsistent parsing across engines. 𝗧𝗲𝗺𝗽𝗼𝗿𝗮𝗹 fixes all of it: → Immutable objects → First-class timezone support via ZonedDateTime → Nanosecond precision → Sane month indexing (January = 1) // before: guess what month this is new Date(2026, 3, 14) // April. obviously. // after Temporal.PlainDate.from({ year: 2026, month: 4, day: 14 }) Still experimental and Stage 3, but enabled by default — no flags needed. This is where moment.js and date-fns start losing their reason to exist for most use cases. Releases April 22. PR #61806 if you want the details. #nodejs #javascript #webdev #temporal
To view or add a comment, sign in
-
-
A new write-up from Invaders breaks down Critical protobuf.js flaw turns untrusted schemas into JavaScript code execution. A critical protobuf.js vulnerability allows attacker-controlled protobuf definitions to trigger JavaScript code execution, putting Node.js applications and transitive dependencies at risk when they load untrusted schemas. What stands out here is the practical defender impact and why this kind of issue should be prioritized quickly. Read the full analysis: https://lnkd.in/daHrG72G
To view or add a comment, sign in
-
-
For years, sorting an array in JavaScript has been a source of subtle bugs. The `.sort()` method, while functional, mutates the original array in place. This often leads developers to create a copy first, usually with the spread operator `[...]`, before sorting. This "copy-then-sort" pattern is verbose and easily forgotten, especially in complex applications where arrays are passed around. If you forget the copy, you inadvertently modify data in other parts of your program, leading to hard-to-trace bugs and unexpected side effects that can really tank your productivity. Enter `Array.toSorted()`. This modern, immutable alternative returns a new sorted array without touching the original. It's cleaner, safer, and exactly what developers have needed for handling data integrity. It prevents accidental data corruption and makes your code much more predictable. Are you still writing it the old way? #javascript #webdevelopment #frontend #cleancode #js
To view or add a comment, sign in
-
-
🚀 JavaScript Output Prediction Challenge What will be the output? 🤔 💡 Important Behaviour: 👉 JavaScript executes code line by line 👉 The very first line throws the following: ❌ ReferenceError: a is not defined So in reality, the programme stops immediately and nothing else runs. 📌 Now, let’s understand what would happen inside the function (ignoring the first error): 👉 Before execution, JS does Hoisting (memory creation phase) Inside the function: var a → hoisted and initialized as undefined let b → hoisted but kept in Temporal Dead Zone (TDZ) (not accessible yet) 👉 Execution phase: "1:" → undefined (Because 'a' exists but not assigned yet) "2:" → ❌ ReferenceError (because b is in TDZ) After assignment: a = 10 b = 20 "3:" → 10 "4:" → 20 🔥 Core Concepts: JS has 2 phases → Memory Creation + execution. var → hoisted + usable as undefined let/const → hoisted but blocked by TDZ 💬 If you got this right, your JS fundamentals are solid 👇 #JavaScript #Hoisting #Frontend #CodingChallenge #WebDevelopment
To view or add a comment, sign in
-
-
𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝘁𝗵𝗲 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗘𝘃𝗲𝗻𝘁 𝗟𝗼𝗼𝗽 JavaScript runs one thing at a time. One slow task freezes your screen. You wonder how apps stay fast. The Event Loop solves this. It manages three main parts. - Call Stack: Runs your code line by line. - Web APIs: Handles timers and API calls. - Queues: Holds callbacks until they run. Queues have levels. - Microtasks: Promises. These have high priority. - Macrotasks: Timers and DOM events. These have low priority. How it works. 1. Sync code runs on the stack. 2. Async tasks move to Web APIs. 3. Finished tasks move to queues. 4. The Event Loop waits for the stack to empty. 5. It pushes microtasks first. 6. It pushes macrotasks last. Look at this example. console.log(Start) setTimeout(Timeout, 0) Promise.then(Promise) console.log(End) The output is: Start End Promise Timeout Why? Start and End run first. The Promise is a microtask. It runs next. The timeout is a macrotask. It runs last. A common mistake is thinking setTimeout 0 runs immediately. It does not. It waits for the stack to empty. It waits for all microtasks to finish. This logic stops async bugs. Understand the loop to write better code. Source: https://lnkd.in/gjBYnFZB
To view or add a comment, sign in
-
What is the difference between shallow copy and deep copy? Copying objects in JavaScript is not always what it seems. A `shallow copy` duplicates only the first level. Nested objects are still shared by reference. A `deep copy` duplicates everything recursively. Why did this happen? - The top-level object was copied - But `address` still points to the same reference To fully isolate data, a deep copy is required. Understanding this is critical when: - Managing state - Avoiding unintended mutations - Debugging shared data issues The behaviour is subtle — but the impact is everywhere. #Frontend #JavaScript #WebDevelopment #SoftwareEngineering
To view or add a comment, sign in
-
-
𝗝𝗦 𝗚𝗲𝗻𝗲𝗿𝗮𝘁𝗼𝗿𝘀 𝗳𝗼𝗿 𝗖𝗼𝗻𝗰𝘂𝗿𝗿𝗲𝗻𝗰𝘆 JavaScript runs on one thread. Async code often feels messy. You started with callbacks. You moved to Promises. Now you have Generators. Generators use the function* syntax. They use the yield keyword. This lets you pause a function. You resume it later. This is how you build coroutines. Why use this method? - Your async code looks like sync code. - You use try and catch for errors. - You keep state across pauses. - You stop callback hell. Real use cases: - Koa.js uses them for middleware. - Game devs use them for smooth animations. - Data streams use async generators for large sets. Watch your performance: - Use fewer yields. - Batch your tasks. - Avoid deep nesting. This tool makes your code cleaner. It helps you manage async flows. Source: https://lnkd.in/gMnSjPEY
To view or add a comment, sign in
More from this author
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development