Day 13 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2621 — Sleep Today’s challenge explored the basics of asynchronous timing in JavaScript — creating a custom sleep() function that pauses execution for a given duration using promises. Here’s my solution 👇 async function sleep(millis) { return new Promise(resolve => setTimeout(resolve, millis)); } This simple problem reinforces how promises and setTimeout() work together to handle delays asynchronously. Understanding this helps build a solid foundation for mastering async behavior in JavaScript. Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #AsyncAwait #Promises #Programming #Developers #Learning
"Creating a custom sleep() function with promises and setTimeout()"
More Relevant Posts
-
Day 12 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2723 — Add Two Promises Today’s problem was all about working with asynchronous operations in JavaScript — specifically how to handle multiple promises efficiently. Here’s my solution 👇 var addTwoPromises = async function(promise1, promise2) { const [a, b] = await Promise.all([promise1, promise2]); return a + b; }; This challenge reinforced how Promise.all() allows us to run promises in parallel, waiting for all of them to resolve before proceeding — a key concept in optimizing asynchronous workflows. It’s a clean and elegant way to handle multiple async tasks without unnecessary delays. Try it out here: https://lnkd.in/g6WC5mu7 #JavaScript #LeetCode #CodingChallenge #LearningJourney #30DaysOfCode #AsyncAwait #Promises #Programming #Developers #Learning
To view or add a comment, sign in
-
-
JavaScript Quirks Every Developer Should Know Understanding these "funny" behaviors isn't just entertaining it's essential for writing better code: - - Why [] == ![] is true (type coercion) - Why 0.1 + 0.2 ≠ 0.3 (floating-point precision) - Why sort() doesn't work as expected (alphabetical default) These quirks teach us valuable lessons about JavaScript's underlying mechanics. What JS behavior caught YOU off guard when you first started? Share your stories! #JavaScript #WebDevelopment #TechEducation #LearnToCode #Programming
To view or add a comment, sign in
-
Just published a beginner-friendly guide to understanding function binding in JavaScript! If you've ever wondered why `this` becomes undefined in callbacks, this article breaks it down with simple examples. Perfect for developers learning JavaScript or anyone who needs a refresher on bind() 💻 https://lnkd.in/dmAU3Rhc #JavaScript #WebDevelopment #Programming #Coding
To view or add a comment, sign in
-
Day 6 of #30DaysOfJavaScript: Unlocking the Power of Array Reduction by Building My Own! 🚀 Today’s challenge took me under the hood of one of JavaScript’s most versatile methods—the .reduce() function. Instead of relying on the built-in version, I crafted a custom reducer that processes an array sequentially to accumulate a final result from an initial value. Here’s a glimpse of the solution I created: What stood out today: The elegance of breaking down complex operations into simpler, reusable steps using higher-order functions. Deepened my understanding of how accumulator patterns work in JavaScript and other programming languages. A fresh appreciation for common built-in functions that hide these powerful mechanics behind simple calls. This hands-on experience is a big step forward in mastering JavaScript fundamentals and improving my problem-solving skills. Looking forward to sharing more coding adventures and growing with this community! If you’re also on this journey, feel free to connect and exchange insights. #JavaScript #CodeNewbie #WebDevelopment #LeetCode #AlgorithmPractice #Programming #ContinuousLearning
To view or add a comment, sign in
-
🚀 Cloning in JavaScript using `Object.assign()` (Oop Concepts) JavaScript's `Object.assign()` method can be used for shallow copying of objects. It copies the values of all enumerable own properties from one or more source objects to a target object. However, it only performs a shallow copy, so if the object contains nested objects or arrays, changes to those nested structures in the cloned object will affect the original object. Understanding this limitation is crucial for avoiding unintended side effects. #oopconcepts #programming #coding #tech #learning #professional #career #development
To view or add a comment, sign in
-
-
Day 16 of #30DaysOfJavaScript on LeetCode Today's Challenge: 2637 — Promise Time Limit Today’s challenge focused on controlling asynchronous execution using timeouts. The goal was to wrap any async function with a time limit — if the function doesn't finish in time, it should automatically reject with "Time Limit Exceeded". Here’s my solution: var timeLimit = function(fn, t) { return async function(...args) { const timeOutPromise = new Promise((_, reject) => setTimeout(() => reject("Time Limit Exceeded"), t) ) return Promise.race([fn(...args), timeOutPromise]) } } Try it out here: https://lnkd.in/g6WC5mu7 This exercise helped me understand how to combine Promise.race() with timeouts to enforce execution limits #JavaScript #LeetCode #CodingChallenge #AsyncAwait #Promises #30DaysOfCode #Programming #Developers #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 81 of #100DaysOfCode Today I learned how to create object literals in JavaScript. An object literal lets you store related data as key-value pairs inside curly braces. For example: const car = { brand: "Toyota", year: 2020, color: "red" }; This way, you can easily organize, access, and update complex data as one unit. Object literals are foundational for structuring real-world information in your programs. #JavaScript #ObjectLiterals #Programming #100DaysOfCode
To view or add a comment, sign in
-
-
𝐒𝐭𝐚𝐫𝐭𝐢𝐧𝐠 𝐖𝐞𝐛 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐦𝐞𝐧𝐭? 𝐇𝐞𝐫𝐞’𝐬 𝐖𝐡𝐚𝐭 𝐀𝐜𝐭𝐮𝐚𝐥𝐥𝐲 𝐌𝐚𝐭𝐭𝐞𝐫𝐬 Many beginners get stuck choosing between frameworks, tools, and languages before writing their first line of code. The truth is, none of that matters as much as building consistency. If you’re just starting out: Pick one language (JavaScript is a great choice). Build something small every day a button, a form, a layout. Don’t chase perfection; chase understanding. Everyone starts from zero. The developers you admire today were once Googling “how to center a div.” Keep going. The only difference between a beginner and a pro is persistence. #WebDevelopment #Programming #LearningToCode #DevZapz
To view or add a comment, sign in
-
📘 Chapter 15: Arrays in JavaScript 💻 In this chapter, we explore one of the most essential concepts in JavaScript — the Array 🔢 Arrays allow us to store and manage multiple values in a single variable — making our code cleaner, faster, and more dynamic. ✨ What You’ll Learn: ✅ How to create and access arrays ✅ Add or remove elements with .push(), .pop(), .shift(), .unshift() ✅ Find the length of an array ✅ Loop through arrays using for and forEach() 🚀 Keep learning, keep coding! #JavaScript #WebDevelopment #Coding #Programming #FrontendDevelopment #LearnToCode #100DaysOfCode #CodeNewbie #SoftwareEngineer #Developers #TechCommunity #ArrayInJavaScript #WebDevJourney #CodingLife #JSRoadmap #FullStackDevelopment #TechLearning
To view or add a comment, sign in
-
-
Every JavaScript developer has hit that confusing moment when var starts acting like it has a mind of its own 😅 I still remember spending hours debugging a scope issue… only to find out that var is function-scoped, while let and const are block-scoped. That’s exactly what we break down in our new Instagram video a quick visual guide to mastering var, let, and const, so you’ll never get caught off guard again. 📹 Check out the full video on our Instagram-> link in the comments 👇 #JavaScript #WebDevelopment #CodingTips #LearnToCode #FrontendDevelopment #Programming #TechEducation
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