Here's a question I thought I knew the answer to: What does await really wait for? My answer was always "a Promise." I was shocked to find out I was wrong. await (and Promise.resolve()) doesn't actually check if an object is an instanceof Promise. It just asks one simple question: "Does this object have a .then() method?" If yes, it's treated as a "thenable," and await will happily wait for it. Promise: The official, native object with .then(), .catch(), etc. Thenable: Anything that has a .then() method. So basically: ✅ Every Promise is a Thenable ❌ But not every Thenable is a Promise This is the "duck typing" magic that makes the entire JavaScript async ecosystem work together. Old promise-like libraries can seamlessly interoperate with modern async/await because they all speak the common language of .then(). This simple distinction was a huge "aha" moment for me. 🤯 Did you already know this, or is your mind just as blown as mine was? It’s one of those small things that shows how deep JavaScript really is. No matter how much you learn, there’s always something new waiting to surprise you. 💡 #JavaScript #WebDevelopment #AsyncProgramming #LearningEveryday #Async #Promises #CodingTips
The difference between Promise and Thenable in JavaScript
More Relevant Posts
-
🔄 Day 164 of #200DaysOfCode Today, I revisited another classic JavaScript problem — removing duplicates from an array without using Set() or advanced methods. 💡 While there are modern one-liners that can handle this task in seconds, manually writing the logic helps build a deeper understanding of how arrays, loops, and conditions work together. This small challenge reinforced two key lessons: 1️⃣ Efficiency matters — Writing logic by hand makes you think about time complexity and performance. 2️⃣ Simplicity is strength — The most effective solutions are often the ones built from fundamental principles. 🔁 As developers, it’s not just about knowing shortcuts — it’s about understanding the why behind every concept. Revisiting such basic problems sharpens logical thinking and improves our ability to write cleaner, more optimized code. 🌱 Mastering the basics is not a step backward — it’s the foundation for everything advanced. #JavaScript #CodingChallenge #BackToBasics #164DaysOfCode #LearnInPublic #DeveloperMindset #WebDevelopment #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🧑💻 Exploring JavaScript Promises! As I dive deeper into JavaScript, I recently explored one of its most powerful features — ✨ Promises ✨ 💡 Promises make asynchronous operations easier to manage, helping us write cleaner and more readable code. 😵💫 Instead of getting stuck in callback hell, Promises let us handle tasks step by step — ➡️ First the request ➡️ Then the response ➡️ Finally the result 🧠 Here’s what I found interesting: 🔹 A Promise represents a value that may be available now, later, or never. 🔹 It has 3 states — ⏳ pending, ✅ fulfilled, ❌ rejected. 🔹 We can use .then() and .catch() to handle success and errors. 🔹 And with async/await, our asynchronous code looks super clean and synchronous! 😎 📚 Learning takeaway: Promises aren’t just about syntax — they teach the concept of asynchronous flow control in modern JavaScript and make our code more predictable and maintainable. #JavaScript #WebDevelopment #AsyncProgramming #Promises
To view or add a comment, sign in
-
🚀 #Day5Challenge – Deep Dive into Closures, Async/Await, Scopes & Lexical Environment. Today was all about connecting the dots between some of JavaScript’s most powerful (and tricky) concepts — Closures, Async/Await, Scopes, and the Lexical Environment. It’s the day where everything started to make sense. 🧠 🔹 Closures I explored how functions remember their outer variables — even after the parent function finishes execution. Closures taught me the real meaning of JavaScript’s memory behavior — how inner functions carry a reference to their outer scope, not just a copy. It’s the reason behind features like private variables, event handlers, and data encapsulation. 🔹 Lexical Environment & Scope I understood how each function forms its own lexical environment — a space where variables live and can be accessed by nested functions. Now I can clearly visualize how the scope chain works — how JS searches variables layer by layer (local → outer → global). No more confusion between block scope and function scope! 🔹 Async / Await Then came the twist — bringing Closures and Async/Await together! I learned how async functions still preserve their lexical scope while waiting for promises to resolve. Even when code execution pauses with await, the closure’s context remains intact — that’s how JavaScript ensures continuity and consistency. Today’s biggest win: “I stopped memorizing JavaScript behavior — and started understanding how it thinks.” #Day5Challenge #JavaScript #Closures #AsyncAwait #LexicalEnvironment #Scopes #FrontendDevelopment #WebDevelopment #CodingChallenge #JavaScriptLearning #AsyncJS #DeveloperJourney #CodeWithLogic
To view or add a comment, sign in
-
-
🚀 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗣𝗿𝗼𝗺𝗶𝘀𝗲𝘀 — 𝗧𝗵𝗲 𝗞𝗲𝘆 𝘁𝗼 𝗔𝘀𝘆𝗻𝗰 𝗠𝗮𝘀𝘁𝗲𝗿𝘆! Ever wondered how JavaScript manages to perform tasks like fetching APIs or reading files without freezing the page? 🤔 That’s where Promises come in — your secret weapon for handling asynchronous operations cleanly and predictably. 𝗛𝗲𝗿𝗲’𝘀 𝘄𝗵𝗮𝘁 𝘆𝗼𝘂’𝗹𝗹 𝗹𝗲𝗮𝗿𝗻 𝗶𝗻 𝘁𝗵𝗶𝘀 𝗯𝗿𝗲𝗮𝗸𝗱𝗼𝘄𝗻 👇 ✅ 𝑊ℎ𝑎𝑡 𝑃𝑟𝑜𝑚𝑖𝑠𝑒𝑠 𝑟𝑒𝑎𝑙𝑙𝑦 𝑎𝑟𝑒 — 𝑎 𝑏𝑒𝑡𝑡𝑒𝑟 𝑎𝑙𝑡𝑒𝑟𝑛𝑎𝑡𝑖𝑣𝑒 𝑡𝑜 𝑐𝑎𝑙𝑙𝑏𝑎𝑐𝑘 ℎ𝑒𝑙𝑙 ✅ 𝐻𝑜𝑤 .𝑡ℎ𝑒𝑛(), .𝑐𝑎𝑡𝑐ℎ(), 𝑎𝑛𝑑 .𝑓𝑖𝑛𝑎𝑙𝑙𝑦() 𝑐𝑜𝑛𝑡𝑟𝑜𝑙 𝑎𝑠𝑦𝑛𝑐 𝑓𝑙𝑜𝑤 ✅ 𝑃𝑟𝑜𝑚𝑖𝑠𝑒 𝑐ℎ𝑎𝑖𝑛𝑖𝑛𝑔 𝑓𝑜𝑟 𝑠𝑒𝑞𝑢𝑒𝑛𝑡𝑖𝑎𝑙 𝑡𝑎𝑠𝑘𝑠 ✅ 𝑃𝑟𝑜𝑚𝑖𝑠𝑒.𝑎𝑙𝑙, 𝑃𝑟𝑜𝑚𝑖𝑠𝑒.𝑟𝑎𝑐𝑒 & 𝑃𝑟𝑜𝑚𝑖𝑠𝑒.𝑎𝑙𝑙𝑆𝑒𝑡𝑡𝑙𝑒𝑑 𝑓𝑜𝑟 𝑝𝑎𝑟𝑎𝑙𝑙𝑒𝑙 𝑜𝑝𝑒𝑟𝑎𝑡𝑖𝑜𝑛𝑠 ✅ 𝑅𝑒𝑎𝑙-𝑤𝑜𝑟𝑙𝑑 𝑒𝑥𝑎𝑚𝑝𝑙𝑒𝑠 — 𝑓𝑟𝑜𝑚 𝑓𝑒𝑡𝑐ℎ𝑖𝑛𝑔 𝐴𝑃𝐼𝑠 𝑡𝑜 ℎ𝑎𝑛𝑑𝑙𝑖𝑛𝑔 𝑢𝑠𝑒𝑟 𝑖𝑛𝑝𝑢𝑡 💡 A Promise in JS is like saying, “I’ll do this task — and once I’m done, I’ll let you know whether it succeeded or failed.” Understanding Promises is the foundation for mastering async/await, fetch API, and modern frontend frameworks like React or Vue. 💬 𝑊ℎ𝑎𝑡’𝑠 𝑜𝑛𝑒 𝑃𝑟𝑜𝑚𝑖𝑠𝑒 𝑐𝑜𝑛𝑐𝑒𝑝𝑡 𝑡ℎ𝑎𝑡 𝑓𝑖𝑛𝑎𝑙𝑙𝑦 “𝑐𝑙𝑖𝑐𝑘𝑒𝑑” 𝑓𝑜𝑟 𝑦𝑜𝑢 𝑎𝑓𝑡𝑒𝑟 𝑠𝑡𝑟𝑢𝑔𝑔𝑙𝑖𝑛𝑔 𝑤𝑖𝑡ℎ 𝑖𝑡? 𝑆ℎ𝑎𝑟𝑒 𝑦𝑜𝑢𝑟 𝑚𝑜𝑚𝑒𝑛𝑡 𝑏𝑒𝑙𝑜𝑤 👇 credit-Shivam Dhyani #JavaScript #AsyncProgramming #Promises
To view or add a comment, sign in
-
⚙️ The Illusion of Async Most engineers think async/await makes their JavaScript code run in parallel. It doesn’t. It only makes asynchronous code look synchronous. The truth? JavaScript still runs on a single thread. Here’s what’s really happening 👇 When you use await fetch('/api'), your function doesn’t magically run on another thread. It just tells JS: “Pause me here. Go do other stuff. Come back when you’re done.” While that’s happening: Your async call gets handed off to the browser (network, timer, etc.) JS continues executing other tasks. When the operation finishes, the event loop queues the result Only when the call stack is clear does JS pick it back up So no — async isn’t parallelism. It’s cooperative multitasking — the illusion of concurrency, powered by the event loop. If you want real parallel execution, you’ll need: 🧵 Web Workers (in browsers) ⚙️ Worker Threads (in Node.js) or smart batching via Promise.all() Here’s the line I always remember 👇 > async doesn’t make your code parallel — it makes it patient. 💭 What’s one concept you once thought you understood — until you dug in and realized how it actually works? #JavaScript #AsyncAwait #EventLoop #WebDevelopment #FrontendEngineering #CodingDeepDive #EngineeringMindset #TechExplained
To view or add a comment, sign in
-
🚀 JavaScript Deep Dive — Part 2: Execution Context Ever wondered how JavaScript actually runs your code? 🤔 That’s done through something called an Execution Context — the environment where your code executes. 🧩 Types of Execution Context: 1️⃣ Global Execution Context (GEC) → Created once when the file runs. 2️⃣ Function Execution Context (FEC) → Created each time a function is called. ⚙️ Each has 2 Phases: 1. Creation Phase: Memory is set for variables & functions. Variables = undefined (hoisting). this keyword is set. 2. Execution Phase: Code runs line by line. Variables get real values. 💡 In short: JS runs code inside execution contexts, managed by a call stack — one at a time, top to bottom. #JavaScript #WebDevelopment #Frontend #LearnInPublic #Coding
To view or add a comment, sign in
-
-
🔄 Day 163 of #200DaysOfCode After exploring advanced topics in JavaScript, I decided to slow down and revisit one of the most timeless logic challenges — reversing an array without using the built-in reverse() method. 🌱 It might seem like a simple exercise, but it teaches you something very powerful — how data moves in memory, how to swap values efficiently, and how small logic patterns build the foundation for solving complex problems later on. In JavaScript, it’s easy to rely on built-in functions, but when you write logic manually, you begin to understand the real mechanics behind how things work — and that’s what makes you a stronger developer. 💡 Problems like these remind me that mastery isn’t about how many advanced concepts you know, but how deeply you understand the basics. 🔁 Even experienced developers revisit their roots from time to time — because fundamentals never go out of style. Keep learning. Keep building. Keep evolving. #JavaScript #CodingChallenge #BackToBasics #163DaysOfCode #LearnInPublic #WebDevelopment #DeveloperMindset #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Remember those early days of JavaScript, when chaining multiple asynchronous operations felt like navigating a maze blindfolded? Callback hell was a rite of passage, and debugging felt like an archaeological dig. 🤔 I’ve definitely spent more than a few late nights trying to untangle nested callbacks. That experience taught me the true value of modern async patterns. The shift to 𝗣𝗿𝗼𝗺𝗶𝘀𝗲𝘀 was a game-changer for me. Suddenly, error handling became manageable, and composing operations felt intuitive. It brought so much 𝗰𝗹𝗮𝗿𝗶𝘁𝘆 to what was previously a jumbled mess. And then 𝗮𝘀𝘆𝗻𝗰/𝗮𝘄𝗮𝗶𝘁 arrived. This pattern transformed how I write asynchronous code, making it read almost like synchronous code. It significantly improves 𝗿𝗲𝗮𝗱𝗮𝗯𝗶𝗹𝗶𝘁𝘆 and reduces cognitive load, especially when dealing with sequential operations or conditional logic. I recall one project where we refactored a legacy API integration from deep callback nesting to async/await. The difference in maintainability was astounding. We cut debugging time by half. It reinforced that choosing the right async pattern isn't just about syntax; it’s about sustainable architecture. I’ll drop a simplified code example in the comments to illustrate what I mean. What's your preferred async pattern for complex JavaScript applications, and why? Share your lessons learned or any clever tricks you've picked up! #JavaScript #AsyncPatterns #WebDevelopment #SoftwareEngineering #TechLessons
To view or add a comment, sign in
-
-
𝐓𝐡𝐞 𝐦𝐨𝐬𝐭 𝐜𝐨𝐦𝐦𝐨𝐧 𝐰𝐨𝐫𝐝 𝐢𝐧 𝐉𝐒… 𝐰𝐚𝐬 𝐧𝐞𝐯𝐞𝐫 𝐩𝐥𝐚𝐧𝐧𝐞𝐝. . . . When JavaScript was created, 𝐁𝐫𝐞𝐧𝐝𝐚𝐧 𝐄𝐢𝐜𝐡 had to decide: “𝑾𝒉𝒂𝒕 𝒔𝒉𝒐𝒖𝒍𝒅 𝒂𝒏 𝒖𝒏𝒊𝒏𝒊𝒕𝒊𝒂𝒍𝒊𝒛𝒆𝒅 𝒗𝒂𝒓𝒊𝒂𝒃𝒍𝒆 𝒃𝒆?”, He didn’t overthink it. he literally wrote: 𝐥𝐞𝐭 𝐚; // 𝐮𝐧𝐝𝐞𝐟𝐢𝐧𝐞𝐝 Originally, 𝐮𝐧𝐝𝐞𝐟𝐢𝐧𝐞𝐝 wasn’t even reserved! Developers could overwrite it: undefined = "oops"; 😬 This caused chaos — so later, the ECMAScript spec made undefined immutable. Now it’s a keyword you can’t touch. From a placeholder to a protected value — undefined truly defined itself. 😅 #JavaScript #History #CodingFacts
To view or add a comment, sign in
-
🌀 𝗠𝗮𝘀𝘁𝗲𝗿𝗶𝗻𝗴 `𝗦𝘆𝗺𝗯𝗼𝗹.𝗶𝘁𝗲𝗿𝗮𝘁𝗼𝗿` — Build Your Own Iterable in JavaScript In my latest article for 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗶𝗻 𝗣𝗹𝗮𝗶𝗻 𝗘𝗻𝗴𝗹𝗶𝘀𝗵, I unpack how you can teach your JavaScript objects to behave like arrays — enabling you to use `for…of`, spread syntax, and more. 👉 𝗥𝗲𝗮𝗱 𝗵𝗲𝗿𝗲:(https://lnkd.in/dTNYSmyp Here’s what you’ll take away: ✅ How the `Symbol.iterator` protocol is the invisible engine behind every iterable — arrays, strings, maps, sets. ✅ The step-by-step for turning any object into something you can loop over with ease. ✅ Why mastering iteration opens up a new level of flexibility in your JavaScript tool-belt — making you a more empowered developer. 💡Use this insight to stop 𝗷𝘂𝘀𝘁 𝘂𝘀𝗶𝗻𝗴 objects and start 𝗱𝗲𝘀𝗶𝗴𝗻𝗶𝗻𝗴 them — more power, more clarity, more control. #JavaScript #WebDevelopment #Coding #Iterables #SymbolIterator #LearnToCode #DeveloperMindset
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
#cfbr