hi connections Day 16 of 30: Implementing a Promise Time Limit! Moving deeper into the Asynchronous section of my 30 Days of JavaScript on LeetCode. Today was about adding a "safety net" to our code. 🛠️⏳ The Goal: Wrap an async function so that if it takes longer than a specified time t, it immediately fails with a "Time Limit Exceeded" error. The Lesson: I used Promise.race() to pit the actual function against a custom timeout promise. This pattern is crucial for building resilient systems. Whether it's a web crawler or a high-traffic API, you never want one slow request to block your entire event loop. Control the time, control the performance! 💻🔥 #JavaScript #WebDevelopment #CodingChallenge #LeetCode #Day16 #SoftwareEngineering #AsyncJS #PerformanceOptimization
Implementing Promise Time Limit with JavaScript on LeetCode
More Relevant Posts
-
•I broke my consistency for a while… but I’m back again, and this time with more clarity and discipline ...... Day 29 of my JavaScript journey :- Today was all about deeply understanding how JavaScript handles asynchronous operations and why things sometimes get messy. Here’s what I learned: 🔹Callback Hell •Nested callbacks make code hard to read and maintain •Difficult to debug and scale •Showed me why structured async patterns matter 🔹Asynchronous Task Execution •JavaScript is single-threaded but can handle async tasks efficiently •Operations like API calls, timers, and events don’t block execution •Helped me understand real-world non-blocking behavior 🔹Web APIs (in depth) •Provided by the browser (setTimeout, fetch, DOM events, etc.) •Run outside the JavaScript engine •Push completed tasks to the callback queue 🔹Event Loop & Callback Queue •Event loop continuously checks the call stack and queue •Executes tasks only when the stack is empty •Core mechanism behind async execution #JavaScript #AsyncProgramming #WebDevelopment #LearningInPublic #Day29
To view or add a comment, sign in
-
🚀 𝐃𝐚𝐲 𝟔/𝟏𝟓 𝐨𝐟 𝐌𝐲 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠 𝐒𝐞𝐫𝐢𝐞𝐬 Today I learned about Functions in JavaScript 💡 👉 Functions are reusable blocks of code They help us avoid repeating the same code again and again. 📌 Syntax: function greet() { console.log("Hello!"); } 👉 Calling the function: greet(); // Hello! 📌 Functions with parameters: function greet(name) { console.log("Hello " + name); } greet("Kanishka"); 👉 Functions make code cleaner, reusable, and easy to manage 💻✨ 💬 Question: Have you started using functions in your projects? Let’s learn together 🚀 #JavaScript #WebDevelopment #LearningInPublic #Day6 #FrontendDevelopment
To view or add a comment, sign in
-
-
🚀 Day 4/30 – JavaScript Challenge Solved: Counter II (LeetCode 2665) Today’s problem was all about understanding closures and how functions can maintain their own state in JavaScript. What I learned: 1.How closures help preserve variable values across function calls 2.Creating multiple operations (increment, decrement, reset) using a single function 3.Clean use of arrow functions for concise code Approach: I created a function that stores the initial value and returns an object with three methods: 1.increment() -> increases value 2.decrement() -> decreases value 3.reset() -> resets to initial value All of this works because of closure, where the inner functions still remember the variable n. Key Insight: Closures are powerful when you need to encapsulate data and control how it’s modified — a very common pattern in real-world JavaScript applications. Consistency is the real game here 🔥 Let’s keep building, one day at a time. #Day4 #30DaysOfCode #JavaScript #WebDevelopment #CodingChallenge #LeetCode #Closures #LearningJourney
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 𝟓/𝟏𝟓 𝐨𝐟 𝐌𝐲 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠 𝐒𝐞𝐫𝐢𝐞𝐬 Today I learned about Loops in JavaScript 🔁 👉 Loops are used to run a block of code multiple times. 📌 Types of Loops: 1️⃣ for loop for (let i = 0; i < 5; i++) { console.log(i); } 2️⃣ while loop let i = 0; while (i < 5) { console.log(i); i++; } 👉 Both loops do the same thing, but the use depends on the situation. 📌 Key Difference: for loop → when you know how many times to run while loop → when condition-based looping is needed Loops make coding faster and more efficient 💻✨ 💬 Question: Which loop do you find easier — for or while? Let’s learn together 🚀 #JavaScript #WebDevelopment #LearningInPublic #Day5 #FrontendDevelopment
To view or add a comment, sign in
-
-
"𝗡𝗼𝗱𝗲.𝗷𝘀 𝗶𝘀 𝗮 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗿𝘂𝗻𝘁𝗶𝗺𝗲." 𝗬𝗼𝘂'𝘃𝗲 𝗿𝗲𝗮𝗱 𝗶𝘁 𝟭,𝟬𝟬𝟬 𝘁𝗶𝗺𝗲𝘀, 𝗯𝘂𝘁 𝗱𝗼 𝘆𝗼𝘂 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗴𝗲𝘁 𝗶𝘁? 🧐 The word "Runtime" is a trap because it describes two completely different things: 1️⃣ 𝗔 𝗠𝗼𝗺𝗲𝗻𝘁 𝗶𝗻 𝗧𝗶𝗺𝗲: The execution phase (when those "runtime errors" actually explode). 2️⃣ 𝗔𝗻 𝗘𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁: The engine (V8/JSC) + APIs (Node/Bun/Deno) that let your code run outside the browser. Confusion here leads to "ghost bugs." Mastering the difference is what separates a dev who just "follows tutorials" from one who truly understands 𝗦𝗼𝗳𝘁𝘄𝗮𝗿𝗲 𝗔𝗿𝗰𝗵𝗶𝘁𝗲𝗰𝘁𝘂𝗿𝗲. I’ve written a jargon-free guide to clear the fog. We compare how engines like V8 vs. JavaScriptCore change the game for tools like Node, Deno, and Bun. 👉 𝗦𝗮𝘃𝗲 𝘁𝗵𝗲 𝗶𝗻𝗳𝗼𝗴𝗿𝗮𝗽𝗵𝗶𝗰 𝗯𝗲𝗹𝗼𝘄 as your quick reference guide! 🔗 𝗥𝗲𝗮𝗱𝘆 𝘁𝗼 𝗺𝗮𝘀𝘁𝗲𝗿 𝘁𝗵𝗲 𝗰𝗼𝗻𝗰𝗲𝗽𝘁? Read the full article on the Blueprint blog. 👇 𝗟𝗶𝗻𝗸 𝗶𝗻 𝘁𝗵𝗲 𝗳𝗶𝗿𝘀𝘁 𝗰𝗼𝗺𝗺𝗲𝗻𝘁! #JavaScript #WebDev #NodeJS #SoftwareEngineering #BlueprintBlog
To view or add a comment, sign in
-
-
Fixed a bug today that took hours to understand. API was fine. Frontend looked correct. But data wasn’t showing. Issue? A small mismatch in field names. Lesson: • Always verify API responses • Never assume things are correct Small bugs, big lessons. What did you debug recently? #FullStackDeveloper #WebDevelopment #JavaScript #Debugging #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 9/100 — #100DaysOfCode Diving deeper into JavaScript and understanding how it really works behind the scenes 💻 Today was all about moving from basics to advanced concepts that power real-world applications. 📚 What I learned: 🧠 Core Concepts • Scope — understanding where variables are accessible • Execution Context — how JavaScript runs code step-by-step • Closures — functions remembering their outer scope ⚡ Advanced Concepts • this keyword — context of execution • Object-Oriented JavaScript — structuring code using objects 🔄 Asynchronous JavaScript • Callbacks — handling async tasks • Promises — better async handling • Async/Await — clean and readable async code 🌐 API Handling • Fetch API — getting data from servers • HTTP Basics — request & response understanding 💡 Key Insight: JavaScript is not just a language — it’s an ecosystem for building dynamic, real-world applications. 🔥 Day 9 complete. Learning how real apps communicate and function. #JavaScript #AsyncJS #WebDevelopment #100DaysOfCode #CodingJourney #BuildInPublic
To view or add a comment, sign in
-
-
JavaScript Promises finally clicked for me today — and honestly, the real-life analogy made all the difference. Think of it like ordering food: • Order placed → Pending • Food delivered → Resolved • Order cancelled → Rejected That’s literally how async code behaves behind the scenes. What I found interesting is how Promises simplify "callback hell" into a much cleaner flow using ".then()", ".catch()", and ".finally()". Still wrapping my head around async/await, but this feels like a solid step forward. Curious — what helped you understand async JavaScript better? #JavaScript #WebDevelopment #AsyncProgramming #CodingJourney
To view or add a comment, sign in
-
-
Day 12/100 of JavaScript 🚀 Today’s topic: async / await "async" and "await" provide a cleaner way to work with Promises and write asynchronous code that looks like synchronous code 📍Basic example async function getData() { const res = await fetch("https://lnkd.in/gCA7VyNQ"); const data = await res.json(); console.log(data); } 📍With error handling async function getData() { try { const res = await fetch("https://lnkd.in/gCA7VyNQ"); const data = await res.json(); console.log(data); } catch (err) { console.error(err); } } 🔑 Key points : - "async" makes a function return a Promise. - "await" pauses execution until the Promise resolves. - Makes code more readable than ".then()" chaining. async/await simplifies handling asynchronous operations while still using Promises under the hood. #Day12 #JavaScript #100DaysOfCode
To view or add a comment, sign in
-
If a function fires 1000 times, but you only want it to run every 100 calls, there's a neat technique for that. Today I learned about counter-based sampling in JavaScript. Use Cases • sampling analytics events to reduce load • limiting noisy logs or metrics • running expensive work periodically in high-frequency flows How it's different from throttling? Sampling is call-count based → run every N calls Throttling is time-based → run at most once every X ms So if 1000 events fire instantly: • sampling (every 100) → runs 10 times • throttling (200ms) → may run only once Different problems, different tools. #javascript #softwareengineering #frontend #webdevelopment #todayilearned
To view or add a comment, sign in
-
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