🚀 Day 28 - 💡 JavaScript Tricky Question Explanation Promise.resolve(1) .then(x => x + 1) .then(x => { throw x; }) .catch(x => x + 1) .then(x => console.log(x)); ✨ Output: 3 🧠 Explanation: 1️⃣ Promise.resolve(1) 👉 Starts resolved with value = 1 2️⃣ .then(x => x + 1) 👉 1 + 1 = 2 → passed to next then 3️⃣ .then(x => { throw x; }) 👉 throws 2 ❌ → Promise becomes rejected 👉 Skips remaining then and jumps to catch 4️⃣ .catch(x => x + 1) 👉 receives 2 → returns 3 👉 Promise becomes resolved again 5️⃣ .then(x => console.log(x)) 👉 logs final value → 3 📌 Key Points: - throw inside then = reject - catch handles error and can return new value - after catch, chain continues normally #JavaScript #WebDevelopment #Frontend #Coding #JSConcepts
JavaScript Promise Resolution and Error Handling
More Relevant Posts
-
🚀 Day 29 - 💡 JavaScript Tricky Question Explanation let a = [1,2,3]; delete a[1]; console.log(a); console.log(a.length); 👉 Output: ``` [1, empty, 3] 3 ``` 👉 Explanation: * `delete` removes the value but does NOT reindex the array * It creates a hole (empty slot) instead of shifting elements * So, `length` remains 3 ⚠️ Use `splice()` if you want to remove and shift elements #JavaScript #WebDevelopment #Frontend #CodingInterview #JSConcepts
To view or add a comment, sign in
-
Hey network! 👋 I’ve been diving into learning JavaScript recently and wanted to share my latest practice project: a classic Simon Says Game! 🎮 Building this was a fantastic way to get hands-on experience with Vanilla JS, specifically focusing on DOM manipulation, event handling, and sequence logic. It was a fun challenge keeping track of the memory arrays and user inputs! 💻 Check out the code here: https://lnkd.in/gwGmr_37 🔗 Let's connect: https://lnkd.in/gtzKeBxq Thoughts and feedback are always welcome! #JavaScript #WebDevelopment #Frontend #CodingJourney #LearningToCode #Projects
To view or add a comment, sign in
-
Just built the classic Snake Game using HTML, CSS, and JavaScript 🐍 The logic behind it was really interesting — especially handling movement, detecting collisions, and making the snake grow after eating food. This project helped me improve: • JavaScript logic building • DOM manipulation • Game loop concepts Still learning and exploring 🚀 Would love to hear your feedback! #JavaScript #WebDevelopment #Frontend #Projects #Learning
To view or add a comment, sign in
-
🧠 Day 18 of 21days challenge JavaScript WeakMap ⚡ WeakMap is a collection where keys must be objects. It helps in memory management because keys are weakly referenced. For easy understanding :- WeakMap = object keys only Garbage collected if no other references Useful to store private data 👉 That’s how memory leaks can be prevented This changed how I manage objects efficiently 🚀 #JavaScript #WeakMap #InterviewPrep #Frontend
To view or add a comment, sign in
-
-
🚀 Day 30 - 💡 JavaScript Tricky Question Explanation const arr = [4, 10, 2, 8]; const result = arr.find(num => num > 5) + arr.findIndex(num => num > 5); console.log(result); 👉 Output: 11 👉 Explanation: * find() returns the first value > 5 → `10` * findIndex() returns its index → `1` * Final result → `10 + 1 = 11` ⚡ Both stop at the **first match** #JavaScript #WebDevelopment #Frontend #CodingInterview #JSConcepts
To view or add a comment, sign in
-
One of the most underrated JavaScript concepts I have come across is microtask starvation. Most of us know that promises run before things like setTimeout. That part is simple. But the interesting part is what happens when you keep adding microtasks continuously. ```js function loop() { Promise.resolve().then(loop); } loop(); setTimeout(() => { console.log("This will never run"); }, 0); ``` What is happening here? Every time the microtask runs, it schedules another one. The event loop keeps clearing microtasks and never moves to the macrotask queue. Result: setTimeout never runs UI updates can get blocked The app can feel frozen without clear errors The real takeaway is this Microtasks do not give control back to the event loop easily. If you use them carelessly in recursive patterns, you can block everything else. In some cases, it is actually better to use setTimeout or similar approaches to let the system breathe. This is not something you see often in tutorials, but it can quietly cause real production issues. #JavaScript #EventLoop #Frontend #WebPerformance
To view or add a comment, sign in
-
🎮 Built a Simon Says Game using HTML, CSS & JavaScript I recently built a memory-based game where users have to repeat an increasing sequence of colors. I created this project while learning from #ApnaCollege, and it helped me strengthen my JavaScript fundamentals. 🔧 Key Features: • Interactive UI with color-based buttons • Keyboard event to start the game • Level progression system • Game-over and restart functionality 💡 What I learned: • DOM manipulation and event handling • Writing game logic step-by-step • Improving UI using HTML & CSS 🔗 Live Demo: https://lnkd.in/gJKbbDHq I would love to hear your feedback and suggestions to improve this further. #WebDevelopment #JavaScript #Frontend #Projects #LearningJourney #100DaysOfCode
To view or add a comment, sign in
-
-
JS Pop Quiz: Did we just overwrite the Admin?! Let’s see who really understands JavaScript memory allocation! 👨💻👩💻 Look at the code snippet from @codewithsarir. We have a user1 object. We assign it to user2, and then change user2's role to 'Guest'. Question: What does console.log(user1.role) actually print? A) 'Admin' (Because we only changed user2) B) 'Guest' (Because they share the same reference) C) undefined D) It throws a TypeError Hint: Think about how JavaScript handles Objects versus Primitive types like strings. Does = make a copy, or just point to the same address? 🤔 Drop your guess in the comments before you test it in your IDE! 👇 Hashtags: #JavaScript #CodingQuiz #WebDesign #ProgrammerLife #Developers #LearnToCode #JS #Frontend #creators #codinglife #programmer
To view or add a comment, sign in
-
-
🎨 I got tired of recoloring SVGs one at a time. You know that thing where you need 30 icons in a new brand color and you're sitting there doing find-and-replace on hex codes file by file? I kept doing that for way too long before I thought, okay, I should just automate this. So I built SVG Batch Recolor Tool. Here's how it works: 📋 Paste a bunch of SVG URLs 🎯 Pick a hex color ⚡ Hit recolor — all fills, strokes, and inline styles update instantly 👀 Live preview grid so you see what you're getting 📦 Download individually or grab everything as a ZIP It fetches the SVGs server-side (because CORS will ruin your afternoon otherwise), does the recoloring client-side with regex, and bundles the output with jszip. 🛠 Built with: Next.js 15 · React 19 · Tailwind v4 Honestly it's a simple tool. I just couldn't find one that worked the way I wanted, so here we are. The whole thing is open source 👇 🔗 Link: https://lnkd.in/gK-QQwi7 ♻️ Repost if this could save someone's afternoon. #webdev #nextjs #react #opensource #svg #developertools #frontend #javascript #typescript
To view or add a comment, sign in
-
-
🚀 Just built a simple yet fun game using HTML, CSS & JavaScript! It’s a Bat–Ball–Stump game where the user selects an option and the computer makes a random choice 🎮 👉 Rules are simple: Bat 🆚 Ball → User wins Ball 🆚 Stump → User wins Stump 🆚 Bat → User wins This project helped me understand: ✔️ DOM manipulation ✔️ Event handling ✔️ Logic building Small project, but a big step in my learning journey 💻✨ Would love your feedback! #WebDevelopment #JavaScript #CodingJourney #Projects #FrontendDeveloper
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