🔥 Async/Await vs Promise chaining: they look the same… until you predict the logs 😅 ❓ What’s the output order? A) A B F D C E B) A D B C F E C) A B D F C E D) A B F C D E ❓If we change await Promise.resolve() to await null, does the order change? 💬 Drop your answers + reasoning 👇 #CodeSnatch #javascript #asyncawait #promises #eventloop #interviewprep
Async/Await vs Promise Chaining: Output Order and Null Handling
More Relevant Posts
-
Why await obj calls obj.then()? You might have seen this surprising JavaScript behavior: An object with a .then() method (a thenable) gets treated like a Promise when used with await. This happens because the JS engine follows a spec rule: if an object has a .then() method, it is considered “Promise‑like.” Internally the engine effectively calls: obj.then(resolve, reject) even if obj isn’t a real Promise. 😶 ⚠️ This is why Thenable attacks are possible. #React #Javascript
To view or add a comment, sign in
-
-
JAVASCRIPT NOTES — PART 5 Some JavaScript bugs aren’t about logic — they’re about understanding how the language behaves internally. This post covers: • Stack vs Heap (how memory is handled) • Shallow vs Deep copy • The real behavior of the `this` keyword • Garbage collection basics • Debouncing & Throttling for UI performance These are the concepts that explain why code behaves the way it does. Once memory and execution flow are clear, JavaScript becomes far more predictable. #JavaScript #WebDevelopment #FrontendDeveloper #InterviewPrep #LearningInPublic #Debouncing #Prototypes #Consistency
To view or add a comment, sign in
-
Managing multiple local projects with different ports can get messy quickly. Portless by Vercel Labs solves this by replacing ports with clean, named localhost URLs like api.myapp.localhost. No port conflicts, clearer tabs, and a smoother development workflow. #WebDevelopment #DeveloperTools #SoftwareDevelopment #JavaScript #DevExperience https://lnkd.in/gJGABYB3
To view or add a comment, sign in
-
The spread operator looks like this: ... The rest operator looks like this: ... They're identical. But they do opposite things. Spread = Expands outward Rest = Collects inward I wrote a detailed guide breaking down both with real examples: Array & object spreading patterns Rest parameters & destructuring Practical use cases (React, APIs, function forwarding) Why context matters Simple rule: Use spread to unpack. Use rest to gather. 🔗 Read here: https://lnkd.in/gnMgH-zR More JavaScript fundamentals on Hashnode: https://lnkd.in/gAwxuryw Inspired by @Hitesh Choudhary @Piyush Garg @ChaiCode #JavaScript #ES6 #WebDevelopment
To view or add a comment, sign in
-
-
🚀 DSA Journey — Remove Duplicates from an Array (JavaScript) Aaj ka simple but important DSA question 👇 Q4.) Problem: Remove duplicate elements from an array while keeping the same order. 📌 Example: Input → [4, 2, 7, 2, 9, 4, 1, 7, 3] Output → 4 2 7 9 1 3 💡 Approach (Simple Flow): ➡️ Two loops use kiye: 1️⃣ Outer loop → current element check karne ke liye 2️⃣ Inner loop → previous elements se compare karne ke liye ✔️ Har element ko uske previous elements se compare kiya ✔️ Agar match mil gaya → duplicate mark karke skip ✔️ Agar duplicate nahi mila → output me include kiya 🔥 Important Point: Single pass logic with nested comparison Time Complexity → O(n²) Space Complexity → O(1) Small steps daily = strong logic building 💪 #DSA #JavaScript #CodingJourney #LearnInPublic #ProblemSolving
To view or add a comment, sign in
-
-
Inconsistent syntax in a #React project almost cost me hours of debugging. In store.js, I used set-people, while in Home.jsx, I used set_people. It took a while to catch it. The problems is, after changing both to set_people, the store is now inconsistent since other cases in this switch statement use an underscore. I may change all to an underscore to keep them the same. This seems to be more common among developers than the dash when using storeReducer, despite camel case being most recommended in #JavaScript in general.
To view or add a comment, sign in
-
-
⚡ JavaScript Concept: Promises vs. Async/Await Stop the callback confusion! Choose the right tool for your async code. 🚀 🟢 Promises → The Foundation Action: Handles async operations via .then() and .catch(). Best for: Simple API fetches and parallel tasks. 🔴 Async/Await → The Standard Action: Cleaner syntax that reads like synchronous code. Best for: Complex logic and sequential API calls. #javascript #frontenddevelopment #reactjs #webperformance #webdevelopment
To view or add a comment, sign in
-
-
A small but common mistake when working with asynchronous JavaScript: forgetting await. Everything in the code can look correct, the function is async, the logic makes sense, but without await, the result you expect never arrives when you need it. It’s a simple oversight, but it can cause confusing behavior when working with APIs or database calls. Sometimes the difference between a bug and a working feature is just one keyword. #JavaScript #AsyncAwait #SoftwareDevelopment #WebDevelopment #Debugging #DeveloperExperience
To view or add a comment, sign in
-
-
⚡ JavaScript Concept: Promises vs Async/Await Say goodbye to callback confusion and write cleaner async code 🚀 🟢 **Promises → The Foundation** Use `.then()` and `.catch()` to handle asynchronous operations. 👉 Ideal for simple API calls and running tasks in parallel. 🔴 **Async/Await → The Modern Standard** Provides a cleaner, more readable syntax that feels like synchronous code. 👉 Best suited for complex logic and sequential API flows. #Javascript #frontenddevelopment #Angular #AngularTips #webdevelopment #webperformance #SoftwareEngineering
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
💡 Tip: await always yields back to the event loop and schedules the rest of the async function as a microtask, even if you await a non-promise value like null.