<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Asim Khan</title>
    <description>The latest articles on DEV Community by Asim Khan (@asimkhan0).</description>
    <link>https://dev.to/asimkhan0</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F464509%2F8a2b7be2-320b-4428-8b03-a17dee8e1154.jpeg</url>
      <title>DEV Community: Asim Khan</title>
      <link>https://dev.to/asimkhan0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asimkhan0"/>
    <language>en</language>
    <item>
      <title>From Web Apps to AI Wonders: Your JavaScript Guide to Large Language Models!</title>
      <dc:creator>Asim Khan</dc:creator>
      <pubDate>Sat, 16 Aug 2025 05:04:30 +0000</pubDate>
      <link>https://dev.to/asimkhan0/from-web-apps-to-ai-wonders-your-javascript-guide-to-large-language-models-28lf</link>
      <guid>https://dev.to/asimkhan0/from-web-apps-to-ai-wonders-your-javascript-guide-to-large-language-models-28lf</guid>
      <description>&lt;h2&gt;
  
  
  Intro: Hey JS Devs! AI's Calling, and Guess What? You're Already Ready.
&lt;/h2&gt;

&lt;p&gt;The hype surrounding Large Language Models (LLMs) like ChatGPT, Gemini, and Claude is not just media fluff; these models are genuinely reshaping industries. The question isn't whether AI will impact your work, but how. And here's a provocative thought: your JavaScript skills are not just relevant, they're a secret weapon.&lt;/p&gt;

&lt;p&gt;For too long, the AI narrative has been dominated by Pythonistas. But JavaScript's ubiquitous presence, its unmatched flexibility, makes it a compelling choice, perhaps &lt;em&gt;the&lt;/em&gt; choice, for crafting AI applications. This isn't about replacing Python in core AI research; it's about leveraging the power of LLMs within the web ecosystem, where JavaScript reigns supreme.&lt;/p&gt;

&lt;p&gt;Consider this journey an intellectual experiment. We'll dissect LLMs, not as black boxes, but as tools ready to be wielded. We'll traverse the historical landscape, examining the curious twists and turns that have led us to this moment. And, crucially, we'll confront the thorny ethical considerations that demand our attention. So, prepare to infuse your code with a touch of artificial intelligence.&lt;/p&gt;

&lt;h2&gt;
  
  
  LLMs 101: What They Are &amp;amp; How They Work (Minus the PhD!)
&lt;/h2&gt;

&lt;p&gt;At their heart, Large Language Models are sophisticated predictive engines. They've ingested vast quantities of text, learning intricate patterns in human language. This allows them to generate text, translate languages, answer questions, and even produce code with surprising fluency.&lt;/p&gt;

&lt;p&gt;Think of their capabilities as a suite of superpowers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chatbots &amp;amp; Conversational AI:&lt;/strong&gt; The most conspicuous application, enabling human-like interactions.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Creation:&lt;/strong&gt; From generating marketing copy to drafting blog posts, LLMs are becoming writing assistants.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summarization &amp;amp; Q&amp;amp;A:&lt;/strong&gt; Distilling complex information into digestible summaries.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Translation:&lt;/strong&gt; Bridging linguistic divides with ever-increasing accuracy.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Generation &amp;amp; Analysis:&lt;/strong&gt; An intriguing possibility—LLMs as coding companions.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To truly harness these powers, one must grasp a few fundamental concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tokens &amp;amp; Embeddings:&lt;/strong&gt; The transformation of language into numerical representations that the AI can process.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt Engineering:&lt;/strong&gt; The subtle art of crafting prompts that elicit the desired responses from the LLM.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-tuning:&lt;/strong&gt; Adapting a pre-trained LLM to a specific domain or task.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RAG (Retrieval-Augmented Generation):&lt;/strong&gt; Equipping the LLM with access to external knowledge sources to enhance its responses.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function Calling &amp;amp; Agents:&lt;/strong&gt; Empowering the LLM to interact with external tools and services, effectively turning it into an intelligent agent.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A Quick Trip Down AI Memory Lane: How We Got Here (and Why JS is Now in the Game)
&lt;/h2&gt;

&lt;p&gt;The pursuit of artificial intelligence has been a long and winding road, marked by periods of intense excitement and profound disillusionment.&lt;/p&gt;

&lt;p&gt;The early days (1950s-1970s) were characterized by a focus on symbolic AI, with programs like ELIZA attempting to simulate human conversation through rule-based pattern matching. Alan Turing's famous intelligence test set the stage, envisioning machines capable of thought.&lt;/p&gt;

&lt;p&gt;The "AI winters" of the 1970s and 1980s saw funding dwindle as early promises failed to materialize. Yet, beneath the surface, progress continued. Expert systems emerged, codifying human knowledge into rule-based systems, and early machine learning algorithms began to show promise. Deep Blue's victory over Garry Kasparov in 1997 was a symbolic triumph.&lt;/p&gt;

&lt;p&gt;The deep learning revolution of the 2010s, fueled by advancements in neural networks and the availability of massive datasets, ushered in a new era. The "Transformer" architecture, introduced in 2017, proved to be a pivotal breakthrough, enabling machines to understand context with unprecedented accuracy.&lt;/p&gt;

&lt;p&gt;While Python became the dominant language for AI research, JavaScript quietly positioned itself as a formidable contender for AI application development. Node.js's asynchronous, non-blocking architecture makes it ideally suited for interacting with cloud-based LLMs. The browser, powered by JavaScript, became the natural interface for AI-powered applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript &amp;amp; LLMs: The Dynamic Duo (Current State of Play)
&lt;/h2&gt;

&lt;p&gt;The convergence of JavaScript and LLMs represents a paradigm shift in AI development. JavaScript is no longer merely a front-end language; it's a full-stack solution for building intelligent applications.&lt;/p&gt;

&lt;p&gt;Several factors contribute to JavaScript's rise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unified Stack:&lt;/strong&gt; The ability to use the same language for front-end, back-end, and AI development simplifies the development process and fosters code reuse.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Node.js Power:&lt;/strong&gt; Node.js excels at handling the asynchronous API calls that are characteristic of LLM interactions.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser-Based AI:&lt;/strong&gt; Frameworks like TensorFlow.js and Transformers.js enable running AI models directly in the browser, enhancing performance, preserving privacy, and reducing costs.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A growing ecosystem of tools is empowering JavaScript developers to build AI-powered applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OpenAI API:&lt;/strong&gt; The gateway to the GPT models, enabling a wide range of AI capabilities.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LangChain.js:&lt;/strong&gt; An orchestration framework that simplifies the construction of complex LLM workflows.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LlamaIndex.js:&lt;/strong&gt; A data connector that allows LLMs to access and reason about private data.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vercel AI SDK:&lt;/strong&gt; A set of tools and libraries that streamline AI integration in Next.js applications.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ollama:&lt;/strong&gt; Run LLMs locally—powerful and private!
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tools are enabling a diverse range of applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intelligent chatbots providing personalized customer support.
&lt;/li&gt;
&lt;li&gt;Automated content generation streamlining marketing efforts.
&lt;/li&gt;
&lt;li&gt;Smart code assistants enhancing developer productivity.
&lt;/li&gt;
&lt;li&gt;RAG systems enabling access to enterprise knowledge bases.
&lt;/li&gt;
&lt;li&gt;Personalized user experiences in AR/VR environments.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Navigating the Minefield: The LLM Controversies &amp;amp; Ethical Puzzles
&lt;/h2&gt;

&lt;p&gt;The rapid advancement of LLMs has brought forth a complex web of ethical challenges that demand careful consideration.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bias Bombs:&lt;/strong&gt; LLMs are trained on vast datasets that reflect societal biases, which can be amplified in the model's outputs.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hallucinations &amp;amp; Fake News:&lt;/strong&gt; LLMs can sometimes generate factually incorrect or nonsensical information, presenting a risk of misinformation.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Privacy Pitfalls:&lt;/strong&gt; The use of sensitive data with public LLMs raises concerns about data leakage and compliance with privacy regulations.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IP Headaches:&lt;/strong&gt; The ownership of content generated by LLMs is a complex legal issue that is still evolving.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Environmental Bill:&lt;/strong&gt; Training large LLMs consumes significant energy, raising concerns about environmental sustainability.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As developers, we have a responsibility to address these ethical challenges through data curation, bias mitigation techniques, transparency, and continuous vigilance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Road Ahead: What's Next for LLMs and JavaScript
&lt;/h2&gt;

&lt;p&gt;The future of LLMs and JavaScript is brimming with possibilities.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Smarter, More Autonomous Agents:&lt;/strong&gt; LLMs will evolve into more sophisticated agents capable of reasoning, planning, and executing complex tasks.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser AI Goes Big (and Smart):&lt;/strong&gt; Expect even more powerful AI models to run directly in the browser, enabling personalized and privacy-preserving experiences.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Natural Language Programming:&lt;/strong&gt; LLMs will enable developers to express their intentions in natural language, blurring the lines between programming and communication.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI as Your Ultimate Co-pilot:&lt;/strong&gt; AI will be deeply integrated into developer tools, providing assistance with code generation, bug fixing, security analysis, and performance optimization.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More Robust Tooling:&lt;/strong&gt; Frameworks like LangChain.js and LlamaIndex.js will continue to evolve, offering richer abstractions and easier integration for cutting-edge AI features.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Focus on Trust &amp;amp; Transparency:&lt;/strong&gt; As AI becomes more powerful, the emphasis will shift towards explainable AI, robust safety measures, and clear accountability.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion: Your JavaScript Journey into AI Begins Now!
&lt;/h2&gt;

&lt;p&gt;The time is ripe for JavaScript developers to embark on their AI journey. The tools are available, the community is growing, and the opportunities are boundless. While the path forward is not without its challenges, the potential rewards are immense. Embrace the challenge, explore the possibilities, and build the next generation of intelligent applications with JavaScript. What amazing AI app will &lt;em&gt;you&lt;/em&gt; build?&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article was written by &lt;a href="https://qubitx.io" rel="noopener noreferrer"&gt;QubitX.io&lt;/a&gt;, a services-based agency helping businesses build AI-powered web applications with JavaScript, Python, and LLMs.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why obj['key'] Works in JavaScript but Breaks in Python</title>
      <dc:creator>Asim Khan</dc:creator>
      <pubDate>Mon, 28 Jul 2025 11:37:40 +0000</pubDate>
      <link>https://dev.to/asimkhan0/why-objkey-works-in-javascript-but-breaks-in-python-2c4n</link>
      <guid>https://dev.to/asimkhan0/why-objkey-works-in-javascript-but-breaks-in-python-2c4n</guid>
      <description>&lt;p&gt;Have you ever switched between JavaScript and Python, wrote some "perfectly fine" code, and got hit with an error like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError: 'AIMessage' object is not subscriptable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I did. And I was simply trying to access &lt;code&gt;.content&lt;/code&gt; from a LangChain AIMessage response. Here's what happened and &lt;strong&gt;why it matters if you're thinking in JavaScript while writing Python.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ☕ The JavaScript Way
&lt;/h2&gt;

&lt;p&gt;In JavaScript, objects are flexible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Asim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      &lt;span class="c1"&gt;// ✅ "Asim"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;   &lt;span class="c1"&gt;// ✅ "Asim"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;strong&gt;dot notation&lt;/strong&gt; and &lt;strong&gt;bracket notation&lt;/strong&gt; work. You can use either depending on the context (e.g., dynamic keys with brackets).&lt;/p&gt;




&lt;h2&gt;
  
  
  🐍 The Python Way
&lt;/h2&gt;

&lt;p&gt;In Python, it &lt;strong&gt;depends on the type&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Dictionary (like JS object)
&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Asim&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;    &lt;span class="c1"&gt;# ✅ Works
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# ❌ AttributeError
&lt;/span&gt;
&lt;span class="c1"&gt;# Object / Class instance
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;

&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Asim&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# ✅ Works
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;         &lt;span class="c1"&gt;# ❌ TypeError
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when I wrote this in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;  &lt;span class="c1"&gt;# ❌ TypeError
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…it failed because &lt;code&gt;state["messages"][-1]&lt;/code&gt; was not a dictionary. It was a LangChain &lt;code&gt;AIMessage&lt;/code&gt; object. The fix?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# ✅
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  💡 TL;DR
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Dot Notation&lt;/th&gt;
&lt;th&gt;Bracket Notation&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;✅ &lt;code&gt;obj.key&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;✅ &lt;code&gt;obj["key"]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Interchangeable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python Dict&lt;/td&gt;
&lt;td&gt;❌ &lt;code&gt;dict.key&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;✅ &lt;code&gt;dict["key"]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Dot works only for objects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python Obj&lt;/td&gt;
&lt;td&gt;✅ &lt;code&gt;obj.prop&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;❌ &lt;code&gt;obj["prop"]&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Brackets work only for dicts&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧠 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;If you're coming from JavaScript and working in Python (especially with tools like LangChain), remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Not everything is a dictionary. And not everything can be accessed with brackets.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This subtle difference can cost hours of debugging if you’re in the zone and writing fast.&lt;/p&gt;

&lt;p&gt;Have you faced a similar gotcha when switching languages? Let me know below 👇&lt;/p&gt;




&lt;h1&gt;
  
  
  python #javascript #langchain #debugging #programmingtips
&lt;/h1&gt;

</description>
      <category>javascript</category>
      <category>python</category>
      <category>beginners</category>
      <category>debugging</category>
    </item>
    <item>
      <title>How to stop a Pending Promise in JavaScript (Timing Based Rejection)</title>
      <dc:creator>Asim Khan</dc:creator>
      <pubDate>Mon, 13 Feb 2023 17:04:57 +0000</pubDate>
      <link>https://dev.to/asimkhan0/how-to-stop-a-pending-promise-in-javascript-timing-based-rejection-1bn5</link>
      <guid>https://dev.to/asimkhan0/how-to-stop-a-pending-promise-in-javascript-timing-based-rejection-1bn5</guid>
      <description>&lt;p&gt;In JavaScript, a promise is an object representing the eventual completion or failure of an asynchronous operation. To stop an ongoing promise, you can use the Promise.race() method to create a new promise that resolves or rejects as soon as one of the promises passed as an argument resolves or rejects. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a new Promise that resolves after 5 seconds&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Promise resolved!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Create a new Promise that rejects after 3 seconds&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stopPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Promise stopped!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Use Promise.race() to stop the ongoing promise after 3 seconds&lt;/span&gt;
&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;race&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;myPromise&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stopPromise&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// Will not be executed&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// Will be executed after 3 seconds&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, myPromise resolves after 5 seconds, but stopPromise rejects after 3 seconds. By passing these two promises to Promise.race(), we create a new promise that will either resolve with the result of myPromise or reject with the error from stopPromise, whichever happens first. In this case, stopPromise rejects after 3 seconds, causing the new promise to reject with the same error. The catch() method is then called with the error message "Promise stopped!".&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
