<?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: 0x4</title>
    <description>The latest articles on DEV Community by 0x4 (@mintech).</description>
    <link>https://dev.to/mintech</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F891134%2Fe07cde6a-ad33-4ddf-8654-934cb3d610b0.jpg</url>
      <title>DEV Community: 0x4</title>
      <link>https://dev.to/mintech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mintech"/>
    <language>en</language>
    <item>
      <title>🚀 Speed Up Your GraphQL Requests with Automatic Persisted Queries (APQ)</title>
      <dc:creator>0x4</dc:creator>
      <pubDate>Tue, 22 Jul 2025 19:34:20 +0000</pubDate>
      <link>https://dev.to/mintech/speed-up-your-graphql-requests-with-automatic-persisted-queries-apq-5ie</link>
      <guid>https://dev.to/mintech/speed-up-your-graphql-requests-with-automatic-persisted-queries-apq-5ie</guid>
      <description>&lt;p&gt;If you're using GraphQL in production, you've probably heard about &lt;strong&gt;Automatic Persisted Queries (APQ)&lt;/strong&gt;. But what are they exactly, and why should you care?&lt;/p&gt;

&lt;p&gt;In this post, we’ll walk through:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why GET requests can improve GraphQL performance&lt;/li&gt;
&lt;li&gt;What APQ is and how it works&lt;/li&gt;
&lt;li&gt;How to implement APQ (with code!)&lt;/li&gt;
&lt;li&gt;How the client knows when to send only the hash&lt;/li&gt;
&lt;li&gt;How to handle fallbacks gracefully&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 Why Use GET Requests in GraphQL?
&lt;/h2&gt;

&lt;p&gt;GraphQL usually uses &lt;code&gt;POST&lt;/code&gt; requests for sending queries. However, when the operation is a &lt;strong&gt;read (query)&lt;/strong&gt;, using &lt;code&gt;GET&lt;/code&gt; has a huge benefit: &lt;strong&gt;HTTP caching&lt;/strong&gt; via browsers, proxies, or CDNs.&lt;/p&gt;

&lt;p&gt;But there’s a catch: &lt;code&gt;GET&lt;/code&gt; requests pass the query in the &lt;strong&gt;URL&lt;/strong&gt;, and URLs have size limits. So for large or complex queries, it can break.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Enter: Automatic Persisted Queries (APQ)
&lt;/h2&gt;

&lt;p&gt;Instead of sending the full query in the URL or request body, you just send a &lt;strong&gt;hash&lt;/strong&gt; of the query. The server:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Checks if it already knows this query&lt;/li&gt;
&lt;li&gt;If yes, executes it and returns the result&lt;/li&gt;
&lt;li&gt;If not, returns a &lt;code&gt;PersistedQueryNotFound&lt;/code&gt; error&lt;/li&gt;
&lt;li&gt;The client then retries, this time with the full query &lt;em&gt;and&lt;/em&gt; the hash&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This avoids sending the full query every time and enables &lt;code&gt;GET&lt;/code&gt; requests with tiny URLs.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 APQ Lifecycle Example
&lt;/h2&gt;

&lt;p&gt;Here’s what happens step-by-step:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. First Request (GET):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /graphql?extensions={
  "persistedQuery": {
    "version": 1,
    "sha256Hash": "abcd1234..."
  }
}&amp;amp;operationName=GetUser
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Server Response:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"errors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PersistedQueryNotFound"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Client Retry (POST):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"query"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"query GetUser { user { id name } }"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"extensions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"persistedQuery"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"sha256Hash"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"abcd1234..."&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"operationName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"GetUser"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Server stores the query and executes it. ✅
&lt;/h3&gt;

&lt;p&gt;On the next identical request, the client only sends the hash!&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ How Does the Client Know?
&lt;/h2&gt;

&lt;p&gt;Most GraphQL clients (Apollo, urql) handle APQ automatically. You don’t need to write extra logic — just enable it in the config.&lt;/p&gt;

&lt;p&gt;Example with Apollo Client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createPersistedQueryLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/client/link/persisted-queries&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpLink&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sha256&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;crypto-hash&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;link&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createPersistedQueryLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;sha256&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HttpLink&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/graphql&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="nx"&gt;link&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apollo will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First send a hash via &lt;code&gt;GET&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Retry with full query via &lt;code&gt;POST&lt;/code&gt; if not found&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 Bonus: Benefits of Using APQ
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Smaller payloads&lt;/li&gt;
&lt;li&gt;Easier CDN caching&lt;/li&gt;
&lt;li&gt;Increased performance for mobile clients&lt;/li&gt;
&lt;li&gt;Optional: block non-whitelisted queries in production&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧯 What If the First Request Fails?
&lt;/h2&gt;

&lt;p&gt;If the server responds with &lt;code&gt;PersistedQueryNotFound&lt;/code&gt;, the client automatically retries with the full query — the user never sees the failure.&lt;/p&gt;

&lt;p&gt;Still, for better DX, you can catch and track these retries for debugging or analytics.&lt;/p&gt;




&lt;p&gt;That’s it! APQ is a clever pattern to boost performance and reduce bandwidth — and it’s surprisingly simple to adopt.&lt;/p&gt;

&lt;p&gt;🧠 &lt;strong&gt;Have questions or tips? Let me know in the comments!&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Methods of Primitives in JavaScript: A Deep Dive</title>
      <dc:creator>0x4</dc:creator>
      <pubDate>Mon, 27 Jan 2025 09:10:06 +0000</pubDate>
      <link>https://dev.to/mintech/understanding-methods-of-primitives-in-javascript-a-deep-dive-j69</link>
      <guid>https://dev.to/mintech/understanding-methods-of-primitives-in-javascript-a-deep-dive-j69</guid>
      <description>&lt;p&gt;JavaScript often feels magical, especially when you can call methods on primitive values like strings or numbers. For 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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&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;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// "HELLO"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, it seems like primitives such as strings, numbers, or booleans are objects with methods. However, primitives are not objects, so how does this work? Let's dive into the fascinating mechanics behind this behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Primitives in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Primitives are the most basic data types in JavaScript. They include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;string&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;number&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bigint&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;boolean&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;symbol&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;null&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These types are immutable, lightweight, and not objects. Unlike objects, primitives do not inherently have methods or properties. Yet, you can still use methods like &lt;code&gt;toUpperCase()&lt;/code&gt; on strings or &lt;code&gt;toFixed()&lt;/code&gt; on numbers. How?&lt;/p&gt;




&lt;h2&gt;
  
  
  The Magic: Wrapper Objects
&lt;/h2&gt;

&lt;p&gt;When you call a method on a primitive, JavaScript temporarily wraps the primitive in a corresponding object type called a &lt;strong&gt;wrapper object&lt;/strong&gt;. These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;String&lt;/code&gt; for strings&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Number&lt;/code&gt; for numbers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Boolean&lt;/code&gt; for booleans&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Symbol&lt;/code&gt; for symbols&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This process enables primitives to behave like objects for the duration of the method call.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;42&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;num&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// "42.00"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Under the Hood:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JavaScript creates a temporary &lt;code&gt;Number&lt;/code&gt; object for the primitive &lt;code&gt;42&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;toFixed(2)&lt;/code&gt; method is called on this temporary object:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nx"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "42.00"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The temporary object is discarded, and the result (&lt;code&gt;"42.00"&lt;/code&gt;) is returned.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process is seamless and invisible to the developer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Lifecycle of a Temporary Wrapper Object
&lt;/h2&gt;

&lt;p&gt;When you call a method on a primitive:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Creation:&lt;/strong&gt; JavaScript creates a temporary wrapper object using the corresponding constructor (e.g., &lt;code&gt;String&lt;/code&gt;, &lt;code&gt;Number&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution:&lt;/strong&gt; The method is executed on this temporary object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Destruction:&lt;/strong&gt; The wrapper object is discarded immediately after the method call, leaving the primitive value unchanged.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This ensures that primitives remain lightweight and immutable while still allowing object-like behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optimization by JavaScript Engines
&lt;/h2&gt;

&lt;p&gt;Modern JavaScript engines (like V8) optimize the process of wrapping primitives to ensure minimal performance overhead. Techniques such as &lt;strong&gt;inline caching&lt;/strong&gt; and &lt;strong&gt;hidden classes&lt;/strong&gt; streamline method lookups and reduce unnecessary object creation.&lt;/p&gt;

&lt;p&gt;For example, instead of creating and destroying a wrapper object every time, engines might reuse internal representations or skip object creation altogether when possible.&lt;/p&gt;




&lt;h2&gt;
  
  
  Null and Undefined: The Exceptions
&lt;/h2&gt;

&lt;p&gt;The primitives &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;undefined&lt;/code&gt; do not have corresponding wrapper objects. As a result, attempting to call methods on them will throw an error:&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;let&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// TypeError: Cannot read properties of null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always ensure that variables are not &lt;code&gt;null&lt;/code&gt; or &lt;code&gt;undefined&lt;/code&gt; before calling methods.&lt;/p&gt;




&lt;p&gt;Have you encountered unexpected behavior when working with primitives? Share your experiences in the comments below!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Do You Know About Transpiling?</title>
      <dc:creator>0x4</dc:creator>
      <pubDate>Thu, 09 Jan 2025 09:07:02 +0000</pubDate>
      <link>https://dev.to/mintech/do-you-know-about-transpiling-2l8f</link>
      <guid>https://dev.to/mintech/do-you-know-about-transpiling-2l8f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Transpiling&lt;/strong&gt; is the process of converting code from one language or advanced version into an older version to make it compatible with older environments or browsers. For instance, if you write code using modern &lt;strong&gt;JavaScript&lt;/strong&gt; (like ES6), the &lt;strong&gt;transpiler&lt;/strong&gt; will convert it into &lt;strong&gt;ES5&lt;/strong&gt; code so that it can be used by older browsers.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎯 Why Do We Need Transpiling?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Support for Older Browsers&lt;/strong&gt;:
Older browsers might not support some of the new features in JavaScript.
&lt;strong&gt;Example&lt;/strong&gt;:
If you write code using &lt;strong&gt;let&lt;/strong&gt; and &lt;strong&gt;const&lt;/strong&gt; (which are new in ES6), an older browser might not recognize them. After transpiling, the code is converted into &lt;strong&gt;var&lt;/strong&gt;, which is supported by older browsers.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// ES6&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// After transpiling to ES5&lt;/span&gt;
   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Improvements in Programming Languages&lt;/strong&gt;:
We can use new features in &lt;strong&gt;JavaScript&lt;/strong&gt; like &lt;strong&gt;async/await&lt;/strong&gt; or even &lt;strong&gt;TypeScript&lt;/strong&gt;, which adds extra capabilities.
&lt;strong&gt;Example&lt;/strong&gt;:
If you write code using &lt;strong&gt;async/await&lt;/strong&gt; in ES6, older browsers can’t handle this feature. But after &lt;strong&gt;transpiling&lt;/strong&gt;, it gets converted into &lt;strong&gt;Promises&lt;/strong&gt;, which are supported by all browsers.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// ES6 with async/await&lt;/span&gt;
   &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&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;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// After transpiling to ES5&lt;/span&gt;
   &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/posts&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
           &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Making Developers’ Work Easier&lt;/strong&gt;:
Tools like &lt;strong&gt;React&lt;/strong&gt; and &lt;strong&gt;TypeScript&lt;/strong&gt; offer better and safer ways to write code.
&lt;strong&gt;Example&lt;/strong&gt;:
In &lt;strong&gt;React&lt;/strong&gt;, we can use &lt;strong&gt;JSX&lt;/strong&gt;, but browsers don’t support &lt;strong&gt;JSX&lt;/strong&gt; directly, so we use &lt;strong&gt;Babel&lt;/strong&gt; to transpile it into regular &lt;strong&gt;JavaScript&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// JSX in React&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, world!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="c1"&gt;// After transpiling to regular JavaScript&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Transpiling&lt;/strong&gt; helps us write code faster and more flexibly without facing issues with old browsers or environments that don’t support certain features.&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Have you used Transpiling in your projects before? Share your experiences with us!&lt;/strong&gt;&lt;/p&gt;

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