<?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: Urmalveer Singh</title>
    <description>The latest articles on DEV Community by Urmalveer Singh (@oggy107).</description>
    <link>https://dev.to/oggy107</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%2F1093269%2Fd9da1f52-8ad4-40b9-a3e9-43c10da69d40.jpeg</url>
      <title>DEV Community: Urmalveer Singh</title>
      <link>https://dev.to/oggy107</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oggy107"/>
    <language>en</language>
    <item>
      <title>Top 3 features in Typescript 5.5</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Thu, 04 Jul 2024 09:30:25 +0000</pubDate>
      <link>https://dev.to/oggy107/top-3-features-in-typescript-55-465n</link>
      <guid>https://dev.to/oggy107/top-3-features-in-typescript-55-465n</guid>
      <description>&lt;p&gt;TypeScript has long been a favorite among developers for its ability to add static typing to JavaScript, enhancing code quality and developer productivity. With each new release, TypeScript continues to evolve, introducing features that simplify development and reduce potential errors. The latest version, TypeScript 5.5, is no exception. This version brings a host of new features and improvements designed to make coding in TypeScript even more efficient and enjoyable. In this blog post, we will explore the top three features of TypeScript 5.5: &lt;strong&gt;better type inference&lt;/strong&gt;, &lt;strong&gt;enhanced regular expression syntax checking&lt;/strong&gt;, and &lt;strong&gt;new ECMAScript Set methods&lt;/strong&gt;. These enhancements underscore TypeScript’s commitment to providing a robust, scalable, and high-performance development experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Better Type Inference
&lt;/h2&gt;

&lt;p&gt;TypeScript 5.5 brings significant improvements to type inference, making the code more robust and reducing the need for explicit type annotations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Improved Inference with filter method
&lt;/h3&gt;

&lt;p&gt;TypeScript now better understands the results of filtering operations, making the types more precise and safe.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previous (typescript 5.4)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxnxzp0fhzqkfk8z614g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvxnxzp0fhzqkfk8z614g.png" alt="typescript 5.4 filter method" width="407" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;New (typescript 5.5)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqemk5a6xjsrj8r9s9kky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqemk5a6xjsrj8r9s9kky.png" alt="typescript 5.5 filter method" width="352" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, previously typescript was not good enough to infer that after filtering out null values &lt;code&gt;nums&lt;/code&gt; only contains numbers but typeScript 5.5 correctly infers this. &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#inferred-type-predicates"&gt;Microsoft devblogs(inferred type predicates)&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Enhanced Control Flow Analysis
&lt;/h3&gt;

&lt;p&gt;TypeScript is now able to narrow expressions of the form &lt;code&gt;obj[key]&lt;/code&gt; when both &lt;code&gt;obj&lt;/code&gt; and &lt;code&gt;key&lt;/code&gt; are effectively constant. This enhancement reduces runtime errors and makes the code easier to maintain.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previous (typescript 5.4)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffdmdidaw13l2ytm62ha.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fffdmdidaw13l2ytm62ha.png" alt="typescript 5.4 control flow" width="793" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;New (typescript 5.5)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xzs2kdv8s5frkhqwxm1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xzs2kdv8s5frkhqwxm1.png" alt="typescript 5.5 control flow" width="617" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, neither &lt;code&gt;obj&lt;/code&gt; nor &lt;code&gt;key&lt;/code&gt; are ever mutated, so TypeScript can narrow the type of &lt;code&gt;obj[key]&lt;/code&gt; to string in &lt;code&gt;if&lt;/code&gt; block after the typeof check and to &lt;code&gt;Array&amp;lt;number&amp;gt;&lt;/code&gt; in &lt;code&gt;else&lt;/code&gt; block which previously it was unable to do so. &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#control-flow-narrowing-for-constant-indexed-accesses"&gt;Microsoft devblogs(control flow narrowing)&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Enhanced Regular Expression Syntax Checking
&lt;/h2&gt;

&lt;p&gt;Regular expressions are now subject to basic syntax checks in typescript 5.5. This enhancement helps catch common issues that were previously overlooked, ensuring that regular expressions adhere to ECMAScript standards. &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#regular-expression-syntax-checking"&gt;Microsoft devblogs(enhanced regex)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Previous (typescript 5.4)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3o6vkclk6zezakxov8hk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3o6vkclk6zezakxov8hk.png" alt="typescript 5.4 regex checks" width="570" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;New (typescript 5.5)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F437tder2by4hg4tjssrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F437tder2by4hg4tjssrs.png" alt="typescript 5.5 regex checks" width="631" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. New ECMAScript Set Methods
&lt;/h2&gt;

&lt;p&gt;TypeScript 5.5 introduces new &lt;code&gt;Set&lt;/code&gt; methods that provide more robust ways to manipulate &lt;code&gt;sets&lt;/code&gt;. Some of these methods, like &lt;code&gt;union&lt;/code&gt;, &lt;code&gt;intersection&lt;/code&gt;, &lt;code&gt;difference&lt;/code&gt;, and &lt;code&gt;symmetricDifference&lt;/code&gt;, take another &lt;code&gt;Set&lt;/code&gt; and return a new &lt;code&gt;Set&lt;/code&gt; as the result.mThe other methods, &lt;code&gt;sSubsetOf&lt;/code&gt;, &lt;code&gt;isSupersetOf&lt;/code&gt;, and &lt;code&gt;isDisjointFrom&lt;/code&gt;, take another &lt;code&gt;Set&lt;/code&gt; and return a &lt;code&gt;boolean&lt;/code&gt;. &lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#support-for-new-ecmascript-set-methods"&gt;Microsoft devblogs(new set methods)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's an example on how to use some of these methods.&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;fruits&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;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apples&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bananas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pears&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oranges&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;applesAndBananas&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;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apples&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bananas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;applesAndOranges&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;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apples&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oranges&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;oranges&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;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;oranges&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;emptySet&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;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// union&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// Set(4) {'apples', 'bananas', 'pears', 'oranges'}&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;union&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Set(3) {'apples', 'bananas', 'oranges'}&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;union&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// intersection&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// Set(2) {'apples', 'bananas'}&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;intersection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Set(0) {}&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;intersection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Set(1) {'apples'}&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;intersection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndOranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// difference&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// Set(3) {'apples', 'bananas', 'pears'}&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Set(2) {'pears', 'oranges'}&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Set(1) {'bananas'}&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;difference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndOranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// symmetricDifference&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// Set(2) {'bananas', 'oranges'}&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;symmetricDifference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndOranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// no apples&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// isDisjointFrom&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDisjointFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDisjointFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndOranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDisjointFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;emptySet&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;emptySet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isDisjointFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;emptySet&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// isSubsetOf&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSubsetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSubsetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSubsetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSubsetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;emptySet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSubsetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;////&lt;/span&gt;
&lt;span class="c1"&gt;// isSupersetOf&lt;/span&gt;
&lt;span class="c1"&gt;////&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSupersetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSupersetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;applesAndBananas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSupersetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oranges&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// true&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;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSupersetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// false&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;emptySet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSupersetOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you for reading! I hope you found these new TypeScript 5.5 features as exciting as I do. 🎉 Happy coding! 🧑‍💻🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>news</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Elysia: A Bun-first Web Framework</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Mon, 05 Feb 2024 07:36:58 +0000</pubDate>
      <link>https://dev.to/oggy107/elysia-a-bun-first-web-framework-1kf3</link>
      <guid>https://dev.to/oggy107/elysia-a-bun-first-web-framework-1kf3</guid>
      <description>&lt;p&gt;Bun is a fast and lightweight JavaScript runtime that aims to be an alternative to Node.js. It supports features like hot reloading, file system APIs, and native modules. But what if you want to build a web application using Bun? That’s where Elysia comes in.&lt;/p&gt;

&lt;p&gt;Elysia is a web framework for Bun that is designed to be performance-focused, simple, and flexible. It has an Express-like syntax, type inference, middleware, file uploads, and plugins for various functionalities like JWT authentication, tRPC, and more. It also claims to be one of the fastest Bun web frameworks, according to its documentation.&lt;/p&gt;

&lt;p&gt;In this article, we will explore some of the major features of &lt;a href="https://elysiajs.com/" rel="noopener noreferrer"&gt;Elysia&lt;/a&gt; and see how to use it to create a simple web application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3l6zijyz7y7fcq6mc1j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm3l6zijyz7y7fcq6mc1j.png" alt="elysia"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;To get started with Elysia, you need to have Bun installed on your system. You can install it using npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g bun
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, you can use the bun create command to generate a new project using the Elysia template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun create elysia myapp
cd myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run the web application in development mode, you can use the bun run dev command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to localhost:3000 should greet you with "Hello Elysia".&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Performance - Static code analysis to generate optimized code&lt;/li&gt;
&lt;li&gt;Unified Type - Shared DTO runtime and compile time validation&lt;/li&gt;
&lt;li&gt;End-to-end Type Safety - Sync your data both client and server&lt;/li&gt;
&lt;li&gt;TypeScript - Extensive type system for full TypeScript experience&lt;/li&gt;
&lt;li&gt;JSX Template Engine - Familiar experience for frontend developer&lt;/li&gt;
&lt;li&gt;Ergonomic by design - Simple and familiar API for building server&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Just Function
&lt;/h2&gt;

&lt;p&gt;One of the core principles of Elysia is that everything is just a function. This means that you can use plain JavaScript functions to define routes, middleware, plugins, and even the Elysia instance itself. This makes Elysia very easy to use, test, and compose.&lt;/p&gt;

&lt;p&gt;For example, to define a simple GET route that returns a text response, you can write:&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;Elysia&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="s1"&gt;elysia&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Elysia&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&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="o"&gt;=&amp;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;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/json&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&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;listen&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Type Safety
&lt;/h2&gt;

&lt;p&gt;To take a step further, Elysia provide Elysia.t, a schema builder to validate type and value in both runtime and compile-time to create a single source of truth for your data-type.&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;Elysia&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&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="s1"&gt;elysia&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Elysia&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/id/:id&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Numeric&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&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;listen&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Standards
&lt;/h2&gt;

&lt;p&gt;Elysia adopts many standards by default, like OpenAPI, and WinterCG compliance, allowing you to integrate with most of the industry standard tools or at least easily integrate with tools you are familiar with.&lt;/p&gt;

&lt;p&gt;For instance, as Elysia adopts OpenAPI by default, generating a documentation with Swagger is as easy as adding a one-liner:&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;Elysia&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;t&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="s1"&gt;elysia&lt;/span&gt;&lt;span class="dl"&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;swagger&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="s1"&gt;@elysiajs/swagger&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Elysia&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;swagger&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/id/:id&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Numeric&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&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;listen&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Plugins
&lt;/h2&gt;

&lt;p&gt;Elysia also supports plugins, which are functions that can extend the functionality of the Elysia instance, the request object, the reply object, or the route methods. For example JWT plugin adds support for using JWT in Elysia handler.&lt;/p&gt;

&lt;p&gt;Install with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun add @elysiajs/jwt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then use it:&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;Elysia&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="s1"&gt;elysia&lt;/span&gt;&lt;span class="dl"&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;jwt&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="s1"&gt;@elysiajs/jwt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&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;Elysia&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;jwt&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="s1"&gt;jwt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Fischl von Luftschloss Narfidort&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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/sign/:name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;params&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;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="na"&gt;httpOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;maxAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;86400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/profile&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="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Sign in as &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;auth&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="s2"&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="p"&gt;}&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;profile&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;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;auth&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unauthorized&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;profile&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="s2"&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;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we have seen how to use Elysia, a Bun-first web framework, to create a simple web application. We have explored some of the major features of Elysia, such as defining routes, using middleware, and using plugins. Elysia is a fast, simple, and flexible web framework that takes full advantage of Bun’s features and APIs.&lt;/p&gt;

&lt;p&gt;I hope this article was helpful for you. If you have any feedback or questions, please let me know. 😊&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>bunjs</category>
      <category>elysia</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Guide to Free Resources for Learning Web Development</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Sun, 17 Dec 2023 06:11:34 +0000</pubDate>
      <link>https://dev.to/oggy107/a-guide-to-free-resources-for-learning-web-development-dee</link>
      <guid>https://dev.to/oggy107/a-guide-to-free-resources-for-learning-web-development-dee</guid>
      <description>&lt;p&gt;Ever dreamed of creating your own corner of the web? Good news – you're just a few clicks away! This blog is your go-to guide for learning web development without spending a dime. We're talking about free resources that turn coding from a mystery into your new superpower. Whether you're just starting or leveling up, join us on this adventure through the world of web development. No fancy degrees needed, just your curiosity and an internet connection. Let's dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. FreeCodeCamp (youtube)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6u5ps7f49zvgzstb8b03.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6u5ps7f49zvgzstb8b03.jpeg" alt="free code camp" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to learning web development for free, FreeCodeCamp's YouTube channel stands out as a treasure trove of tutorials, projects, and insights. Geared towards beginners and seasoned developers alike, this channel brings coding concepts to life through engaging video content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why FreeCodeCamp's YouTube Channel?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Diverse Learning Paths:&lt;/strong&gt; From HTML and CSS basics to advanced JavaScript frameworks, FreeCodeCamp covers a spectrum of topics to cater to every skill level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project-Based Learning:&lt;/strong&gt; Dive into real-world projects that solidify your skills and showcase your coding prowess. The channel's project-focused approach ensures you're not just learning theory but applying it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interview Preparation:&lt;/strong&gt; Navigate the often daunting world of coding interviews with dedicated content that demystifies technical assessments and helps you ace them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay Current:&lt;/strong&gt; Web development is a dynamic field, and FreeCodeCamp keeps its content up-to-date with the latest technologies and trends, ensuring you learn relevant skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended videos
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://youtu.be/Oe421EPjeBE?si=JPqgwJvcoNN_p7I9"&gt;https://youtu.be/Oe421EPjeBE?si=JPqgwJvcoNN_p7I9&lt;/a&gt;&lt;br&gt;
&lt;a href="https://youtu.be/zJSY8tbf_ys?si=1KjT4R1pkNKFMLL4"&gt;https://youtu.be/zJSY8tbf_ys?si=1KjT4R1pkNKFMLL4&lt;/a&gt;&lt;br&gt;
&lt;a href="https://youtu.be/nu_pCVPKzTk?si=JnZ_Ai_iBgKtXldw"&gt;https://youtu.be/nu_pCVPKzTk?si=JnZ_Ai_iBgKtXldw&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. CssBattle (website)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a3m022f10l01zzmc5g8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a3m022f10l01zzmc5g8.png" alt="css battle" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those looking to turn CSS from a styling language into a competitive art form, CSS Battle is the interactive playground you've been waiting for. Forget traditional tutorials; CSS Battle challenges you to showcase your styling prowess by replicating intricate designs using just CSS code.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Get Started
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Visit the Website:&lt;/strong&gt; Head over to &lt;a href="https://cssbattle.dev/"&gt;CSS Battle&lt;/a&gt; and explore the array of challenges waiting for your creative touch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Select a Battle:&lt;/strong&gt; Choose a battle that aligns with your skill level and interests. Battles vary in complexity, allowing you to progress at your own pace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start Styling:&lt;/strong&gt; Dive into the challenge and start crafting your CSS masterpiece. The live preview feature lets you see the impact of your code in real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Submit and Learn:&lt;/strong&gt; Once satisfied with your solution, submit your code. Explore others' solutions to gain insights into alternative approaches and techniques.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. MDN Web Docs (website)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ay79a2eryb4cr45ewn1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ay79a2eryb4cr45ewn1.jpg" alt="MDN Web Docs" width="703" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to authoritative, up-to-date documentation for web development, MDN Web Docs (Mozilla Developer Network) stands as a beacon of comprehensive and reliable information. Maintained by Mozilla, this platform is not just a documentation repository but a dynamic and evolving resource that caters to developers across all skill levels.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why MDN Web Docs?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Extensive Documentation:&lt;/strong&gt; MDN Web Docs covers a wide array of web technologies, including HTML, CSS, JavaScript, and web APIs. Each topic is meticulously documented with clear explanations, code examples, and practical use cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browser Compatibility Information:&lt;/strong&gt; One of the standout features is the inclusion of detailed browser compatibility tables. This ensures that developers are well-informed about how different browsers handle specific features, facilitating cross-browser compatibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tutorials and Guides:&lt;/strong&gt; MDN doesn't just provide dry documentation. It offers tutorials and guides that take you through fundamental concepts and advanced techniques. These resources are designed for both beginners taking their first steps and seasoned developers seeking deeper insights.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regular Updates:&lt;/strong&gt; The web is a dynamic environment, and MDN reflects this by keeping its content updated. As new features are introduced and standards evolve, MDN provides timely information to keep developers abreast of the latest practices.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Use MDN Web Docs
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Navigate the Documentation:&lt;/strong&gt; Visit the &lt;a href="https://developer.mozilla.org/"&gt;MDN Web Docs&lt;/a&gt; homepage and explore the available documentation by technology or feature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Search Functionality:&lt;/strong&gt; Use the powerful search functionality to quickly find information about specific elements, attributes, methods, or concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interactive Examples:&lt;/strong&gt; Many pages feature interactive examples that allow you to modify code directly in the browser and see the live results, providing an immersive learning experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Contribution Opportunities:&lt;/strong&gt; MDN is an open platform, and developers are encouraged to contribute. If you spot an error or have additional insights, you can actively participate in improving the documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. CodePen (website)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foifwugzimjgyewlum76l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foifwugzimjgyewlum76l.png" alt="code pen" width="600" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/"&gt;CodePen&lt;/a&gt; isn't just a platform; it's a vibrant community and a dynamic development environment rolled into one. As an online playground for front-end developers, it opens a portal to a world where creativity meets code. Here's why CodePen is an invaluable resource for developers looking to experiment, learn, and share their coding endeavors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why CodePen?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Instant Prototyping:&lt;/strong&gt; CodePen provides an instant, browser-based coding environment where you can create "pens" (code snippets) in HTML, CSS, and JavaScript. This enables rapid prototyping and experimentation without the need for a complex development setup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Live Previews:&lt;/strong&gt; One of the standout features is the ability to see live previews of your code changes immediately. This instant feedback loop is invaluable for refining designs and troubleshooting issues efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sharing and Collaboration:&lt;/strong&gt; CodePen is a social platform where developers from around the world share their pens. You can explore a vast collection of pens created by others, fork them to make your modifications, and even collaborate with other developers in real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Showcasing:&lt;/strong&gt; Beyond individual pens, CodePen allows developers to showcase entire projects. This makes it an excellent tool for building portfolios, sharing web experiments, and getting feedback from the community.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the vast universe of web development, where innovation and creativity intertwine, the resources explored in this blog serve as your guiding stars.&lt;/p&gt;

&lt;p&gt;Remember, this journey is yours to mold. Whether you're a beginner taking the first steps or a seasoned developer seeking new heights, the beauty of web development lies in its inclusivity and limitless potential. Embrace the challenges, celebrate the victories, and keep pushing the boundaries of what you can create.&lt;/p&gt;

&lt;p&gt;So, with your coding tools in hand and the spirit of curiosity as your compass, venture forth. The web awaits your creations, and the skills you hone today are the building blocks of the digital wonders you'll craft tomorrow. Happy coding! 🚀🌐&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>resources</category>
      <category>learning</category>
    </item>
    <item>
      <title>Getting Started With Github Actions</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Tue, 05 Sep 2023 09:57:02 +0000</pubDate>
      <link>https://dev.to/oggy107/getting-started-with-github-actions-odd</link>
      <guid>https://dev.to/oggy107/getting-started-with-github-actions-odd</guid>
      <description>&lt;p&gt;In the fast-paced world of software development, being able to automate tasks servers as a great advantage. Tasks such as building, testing and deploying can be automated by setting up a continuous integration and delivery (CI/CD) pipeline. There are many CI/CD tools out there but one is built in right into our favorite Github and yes you guessed it right... it's Github Actions.&lt;/p&gt;

&lt;p&gt;Github Actions makes it breeze to build a secure and reliable CI/CD pipeline allowing you to focus more on the actual development of the software. In this article We are going to understand basics of Github Actions and also try to automate testing for a nodejs app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Github Actions
&lt;/h2&gt;

&lt;p&gt;GitHub Actions is a CI/CD platform that allows you to create workflows that build and test every pull request to your repository, or deploy merged pull requests to production. Workflows are defined by a YAML file checked in to your repository and will run when triggered by an event in your repository, or they can be triggered manually, or at a defined schedule. The components of GitHub Actions include workflows, actions, events, jobs, runners and steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  workflows
&lt;/h3&gt;

&lt;p&gt;At the core of GitHub Actions are workflows, which define the automation process for your repository. They include various actions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Actions
&lt;/h3&gt;

&lt;p&gt;Actions are what they sound like. They are reusable units of work within a workflow. They are individual tasks or steps that can be combined to create a custom automation sequence. GitHub provides a marketplace of pre-built actions, and you can also create your own custom actions to suit your specific needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Events
&lt;/h3&gt;

&lt;p&gt;Events acts as triggers for workflows. They determine when a workflow will run. For example on a push to specific repository, pull requests, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jobs
&lt;/h3&gt;

&lt;p&gt;Workflows consist of one or more jobs. Each job represents a unit of work that runs on a specific runner, which can be a virtual machine, a container, or a hosted runner provided by GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  runners
&lt;/h3&gt;

&lt;p&gt;Runners are the execution environments for jobs in GitHub Actions. You can use GitHub-hosted runners, which are provided by GitHub, or set up your own self-hosted runners for more specialized tasks.&lt;/p&gt;

&lt;h3&gt;
  
  
  steps
&lt;/h3&gt;

&lt;p&gt;Steps are the individual tasks within a job that define the actions to be executed. Each job can consist of one or more steps, and these steps are executed sequentially.&lt;/p&gt;

&lt;p&gt;Now that we have basic understanding of Github Actions and its components. Lets try to build a workflow which triggers on a push or pull requests and runs tests for our nodejs app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating A Workflow
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Pre-Requisites
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A github repository&lt;/li&gt;
&lt;li&gt;Nodejs app (code) in the repository&lt;/li&gt;
&lt;li&gt;Tests written for the nodejs code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further steps assumes that all pre-requisites are met.&lt;/p&gt;

&lt;p&gt;To create a Github workflow follow these steps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create &lt;code&gt;github/workflows&lt;/code&gt; directory in root of your folder&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;.yml&lt;/code&gt; file in this directory. You can name this file anything such as &lt;code&gt;ci.yml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copy the following code into &lt;code&gt;ci.yml&lt;/code&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Node.js CI/CD&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;master&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;master&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Checkout code&lt;/span&gt;
      &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt; &lt;span class="c1"&gt;# This allows you to perform actions on the code in repository&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Node.js&lt;/span&gt;
      &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v2&lt;/span&gt;
      &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18&lt;/span&gt; &lt;span class="c1"&gt;# You can specify your desired Node.js version here&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run tests&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm test&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thats it. You have created a simple workflow which will trigger on a push or pull request to master branch of your repository. The workflow above runs on a Github-hosted ubuntu runner.&lt;/p&gt;

&lt;p&gt;You can check out more on what each line in the workflow means and understand syntax at &lt;a href="https://docs.github.com/en/actions/learn-github-actions"&gt;Github Actions docs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Triggering Our Workflow
&lt;/h2&gt;

&lt;p&gt;Now that we have created our workflow to automate testing lets try to trigger it by pushing code into repository.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the &lt;code&gt;Actions&lt;/code&gt; page of your repository and you will see the list of all your workflows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjgqeaqg7nbntfhu7dd2a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjgqeaqg7nbntfhu7dd2a.png" alt="actions page" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make changes to the code and push it to the github using &lt;code&gt;git push&lt;/code&gt; to trigger the workflow. You will see that workflow has been triggered and is performing actions specified in &lt;code&gt;ci.yml&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcfjrgz88z4zo779vw8wr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcfjrgz88z4zo779vw8wr.png" alt="workflow running" width="800" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can click on each run and see the actions and their results&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F326ilqrprlk5b7ugeezf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F326ilqrprlk5b7ugeezf.png" alt="workflow complete" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🎉 Voilà! You have successfully automated your testing and deployed a workflow using Github Actions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you have seen it is super easy to automate tasks such as testing using Github Actions. You should now have basic understanding of Github Actions and ready to incorporate this knowledge in future projects to make your coding journey a bit automated and easy. I hope you liked the article. Stay tuned and Happy Coding 🌟.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>github</category>
      <category>devops</category>
      <category>automation</category>
    </item>
    <item>
      <title>Multithreading in javascript: Introduction to Web Workers</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Mon, 14 Aug 2023 08:36:45 +0000</pubDate>
      <link>https://dev.to/oggy107/multithreading-in-javascript-introduction-to-web-workers-4g31</link>
      <guid>https://dev.to/oggy107/multithreading-in-javascript-introduction-to-web-workers-4g31</guid>
      <description>&lt;p&gt;As we all know javascript is single-threaded, meaning that it can only ever execute one piece of code at a time. When an asynchronous event occurs (like a mouse click, a timer firing, or an XMLHttpRequest completing) it gets queued up to be executed later. In other words, just single thread handles the event loop. While this design simplifies programming, it also introduces limitations, especially when tackling resource-intensive tasks. Computationally intensive tasks, causes applications to become unresponsive or slow. This is where the need for Web Workers becomes evident.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Workers
&lt;/h2&gt;

&lt;p&gt;Web Workers are browser-based threads that enable parallel execution of tasks, allowing heavy computations, data processing, and other resource-intensive operations to occur in the background. Workers run on a separate thread than the main execution thread. Data is sent between the main thread and workers through messages. This separation of tasks into multiple threads not only enhances performance but also maintains the responsiveness of the user interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Web Workers
&lt;/h3&gt;

&lt;p&gt;setting up web workers is pretty easy. Lets get into it.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Setting up project folder and adding HTML
&lt;/h4&gt;

&lt;p&gt;create a project folder and add &lt;code&gt;index.html&lt;/code&gt; in the root of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Web Workers&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"main.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. create javascript file named &lt;code&gt;main.js&lt;/code&gt; in the same folder
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;main.js&lt;/code&gt; contains the main code which will create new web workers and assign tasks to them. We will create an array of numbers from &lt;code&gt;1 to 200_000&lt;/code&gt; and calculate sum of all previous numbers as we iterate through it just to mimic complex work. We will also measure the performance gains when using &lt;code&gt;1&lt;/code&gt; worker vs when using &lt;code&gt;8&lt;/code&gt; workers.&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;msToS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ms&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="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&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;4&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;chunkify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;size&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;

    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;chunks&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;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;work&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;workers&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;chunkify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;work&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;workers&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;tick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;completedWorkers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;worker&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;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./worker.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&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="o"&gt;=&amp;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="s2"&gt;`Worker &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;i&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="s2"&gt; completed`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="nx"&gt;completedWorkers&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;completedWorkers&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;workers&lt;/span&gt;&lt;span class="p"&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;workers&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; workers took &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;msToS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;tick&lt;/span&gt;
                    &lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt; s`&lt;/span&gt;
                &lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&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;main&lt;/span&gt; &lt;span class="o"&gt;=&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;i&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;workers&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="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;workers&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. create javascript file named &lt;code&gt;worker.js&lt;/code&gt; in the same folder
&lt;/h4&gt;

&lt;p&gt;This file contains the actual work to be done by web worker. We will add message event listener and pass an array (single chunk) from &lt;code&gt;run()&lt;/code&gt; method in &lt;code&gt;main.js&lt;/code&gt;.&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="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;message&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="nx"&gt;e&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&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="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;done&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&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;h3&gt;
  
  
  Running Web Workers
&lt;/h3&gt;

&lt;p&gt;Let us start with single web worker and see how much time it takes to complete the work. Make sure &lt;code&gt;workers&lt;/code&gt; variable is set to &lt;code&gt;1&lt;/code&gt; in &lt;code&gt;run()&lt;/code&gt; method in &lt;code&gt;main.js&lt;/code&gt;. Run the project in any browser in open developer console. You will see that single worker took more than a minute to complete the work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7fqp4345vk7uqn43jq6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm7fqp4345vk7uqn43jq6.png" alt="single worker run" width="242" height="41"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets bump up the workers to &lt;code&gt;8&lt;/code&gt;. set &lt;code&gt;workers&lt;/code&gt; variable to &lt;code&gt;8&lt;/code&gt; in &lt;code&gt;run()&lt;/code&gt; method in &lt;code&gt;main.js&lt;/code&gt;. It should look like this&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;workers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the project once more and observe the performance gains. You will see that &lt;code&gt;8&lt;/code&gt; workers completed the work in about &lt;code&gt;18&lt;/code&gt; seconds. This is about 72% performance gain than single worker. Isn't this amazing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fub7r7kqw8x9nr0ekhayf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fub7r7kqw8x9nr0ekhayf.png" alt="8 workers run" width="230" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to play with the code and learn :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Accelerate Your Web3 Projects: Top Libraries, Frameworks and other tools to Explore</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Sun, 06 Aug 2023 16:24:31 +0000</pubDate>
      <link>https://dev.to/oggy107/accelerate-your-web3-projects-top-libraries-frameworks-and-other-tools-to-explore-34c6</link>
      <guid>https://dev.to/oggy107/accelerate-your-web3-projects-top-libraries-frameworks-and-other-tools-to-explore-34c6</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of blockchain and decentralized technologies, Web3 development emerges as a driving force behind the next generation of the internet. Web3 brings forth a paradigm shift, where applications become more transparent, secure, and user-centric through the integration of blockchain and smart contracts&lt;/p&gt;

&lt;p&gt;This article dives into the exciting world of Web3 development, exploring a handpicked selection of essential libraries, frameworks and platforms that empower developers to unleash the full potential of blockchain and decentralized applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://hardhat.org/" rel="noopener noreferrer"&gt;1. Hardhat Framework&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9t3ljjdvga93vmx7fuw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9t3ljjdvga93vmx7fuw.jpg" alt="hardhat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hardhat is one of my favorite tools for web3 development. It is a development environment for Ethereum software. It consists of different components for editing, compiling, debugging and deploying your smart contracts and dApps, all of which work together to create a complete development environment.&lt;/p&gt;

&lt;p&gt;Some of the features that Hardhat offers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hardhat Network:&lt;/strong&gt; A local Ethereum network that simulates the mainnet behavior and allows you to test your code with advanced features such as console logging, stack traces, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardhat Runtime Environment (HRE):&lt;/strong&gt; A JavaScript object that provides access to the Hardhat Network, the project’s configuration, the deployed contracts, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardhat Plugins:&lt;/strong&gt; A system that allows you to extend the functionality of Hardhat with third-party modules, such as testing frameworks, code coverage tools, security analyzers, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardhat Tasks:&lt;/strong&gt; A way to define and execute custom scripts that can interact with the HRE, the Hardhat Network, or any other component of Hardhat.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.npmjs.com/package/ethers" rel="noopener noreferrer"&gt;2. Ethers.js&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69jf1ny6uxvjgcdy76xa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69jf1ny6uxvjgcdy76xa.png" alt="ethers.js"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ethers.js is a JavaScript library for interacting with the Ethereum blockchain and its ecosystem. It is designed to be compact, lightweight, and easy to use. It is another of favorite tools for web3 development.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.openzeppelin.com/" rel="noopener noreferrer"&gt;3. OpenZeppelin&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfcdrdvz8a5cz440ik00.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfcdrdvz8a5cz440ik00.jpg" alt="OpenZeppelin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OpenZeppelin is an open-source platform for building secure dApps on Ethereum and other blockchains. It provides tools, libraries, and services to help you create, manage, and audit your Web3 applications.&lt;/p&gt;

&lt;p&gt;Some of the main products of OpenZeppelin are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;OpenZeppelin Contracts:&lt;/strong&gt; a library of secure and reusable smart contracts that implement the most used ERC standards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenZeppelin Defender:&lt;/strong&gt; a platform to automate your smart contract administration, security, and operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://chain.link/" rel="noopener noreferrer"&gt;4. Chainlink&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbv5whu1l0rbtdckuipxj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbv5whu1l0rbtdckuipxj.jpg" alt="chainlink"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chainlink is a decentralized oracle network that connects blockchains to external systems, such as data sources, APIs, cloud services, etc. It allows smart contracts to access real-world information and events in a secure and reliable way.&lt;/p&gt;

&lt;p&gt;Chainlink is open-source and community-driven. It consists of two main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Chainlink Nodes:&lt;/strong&gt; software that runs on various blockchains and communicates with external systems via adapters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chainlink Core:&lt;/strong&gt; a set of smart contracts that coordinate the network, manage node reputation, and facilitate data delivery and payment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Chainlink supports multiple blockchains and data providers, enabling cross-chain interoperability and scalability. It also offers various solutions for different use cases, such as data feeds, verifiable randomness, proof of reserve, keepers, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://trufflesuite.com/" rel="noopener noreferrer"&gt;4. Truffle&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv0pio0l1au8et64uoqft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv0pio0l1au8et64uoqft.png" alt="truffle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Truffle is a development framework for Ethereum that simplifies the creation, testing, and deployment of smart contracts and decentralized applications (DApps). It is the most popular framework for Ethereum development.&lt;/p&gt;

&lt;p&gt;Truffle provides the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Built-in smart contract compilation, linking, deployment and binary management:&lt;/strong&gt; You can write your smart contracts in Solidity, Vyper, or any other language that compiles to EVM bytecode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated contract testing with Mocha and Chai:&lt;/strong&gt; You can write your tests in JavaScript or Solidity and run them with Truffle’s built-in test runner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive console for direct contract communication:&lt;/strong&gt; You can use Truffle’s console to interact with your deployed contracts, send transactions, call functions, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://moralis.io/" rel="noopener noreferrer"&gt;6. Moralis&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfekcwq1dr17usm4hera.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzfekcwq1dr17usm4hera.png" alt="moralis"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moralis is a web3 development platform that aims to make it easy and fast for developers to create decentralized applications (DApps) on any blockchain .&lt;/p&gt;

&lt;p&gt;Some of the features that Moralis offers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Seamless hosting:&lt;/strong&gt; You can host your DApp on Moralis’ cloud infrastructure and get a fully managed backend, database, and serverless functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-chain APIs:&lt;/strong&gt; You can access real-time and historical data from multiple blockchains, such as Ethereum, Binance Smart Chain, Polygon, etc, with a single API key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Powerful SDKs:&lt;/strong&gt; You can use Moralis’ SDKs to integrate web3 functionality into your DApp, such as authentication, transactions, NFTs, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep index:&lt;/strong&gt; You can query and analyze any on-chain data with Moralis’ deep index, which indexes every transaction, event, and contract on the supported blockchains.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, the array of libraries, frameworks and platforms presented in this article serves as a powerful toolkit for Web3 developers, enabling them to navigate the intricacies of blockchain and decentralized application development.&lt;/p&gt;

&lt;p&gt;I know that the web3 ecosystem is highly active and a lot of new developments are happening daily. So let me know if I’ve missed something in the comments 😃. Happy coding! 👨‍💻&lt;/p&gt;

</description>
      <category>web3</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Demystifying Consensus Mechanisms and Algorithms in Blockchain Technology</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Wed, 02 Aug 2023 11:38:03 +0000</pubDate>
      <link>https://dev.to/oggy107/demystifying-consensus-mechanisms-and-algorithms-in-blockchain-technology-59f</link>
      <guid>https://dev.to/oggy107/demystifying-consensus-mechanisms-and-algorithms-in-blockchain-technology-59f</guid>
      <description>&lt;p&gt;Blockchain technology has revolutionized the way we think about transactions and data storage. Blockchain's ability to achieve consensus in a decentralized and trustless environment is at the core of its revolutionary impact. This is possible thanks to consensus mechanisms and algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Consensus Mechanism?
&lt;/h2&gt;

&lt;p&gt;A consensus mechanism is responsible for ensuring that all nodes in the network agree on the state of the distributed ledger. Consensus mechanisms are essential for maintaining the integrity and security of blockchain networks, and they come in many different forms. In this article, we will explore some of the most popular consensus mechanisms and algorithms in blockchain technology, including Proof of Work (PoW), Proof of Stake (PoS), Delegated Proof Of Stake (DPoS), Proof of Authority (PoA), Practical Byzantine Fault Tolerance (PBFT) and Proof of capacity (PoC). First lets try to understand why do we even need the consensus mechanisms in blockchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need for the Consensus Mechanisms in blockchain
&lt;/h2&gt;

&lt;p&gt;The need for consensus in blockchain technology arises from the fact that it is a distributed system that relies on a network of nodes to validate and verify transactions. Without a consensus mechanism, it would be impossible to ensure that all nodes in the network agree on the state of the distributed ledger. This would lead to inconsistencies and errors in the ledger, which could compromise the integrity and security of the entire system.&lt;/p&gt;

&lt;p&gt;Consensus mechanisms are essential for maintaining the integrity and security of blockchain networks. They ensure that all nodes in the network agree on the state of the distributed ledger, and they prevent malicious actors from tampering with the ledger. Additionally, consensus mechanisms are responsible for adding new blocks to the blockchain, which is how transactions are processed and recorded.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8alw93aw3cjb67mbyye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8alw93aw3cjb67mbyye.png" alt="importance of consensus mechanisms" width="290" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Popular Consensus Mechanisms in blockchain
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Proof of Work (PoW)
&lt;/h3&gt;

&lt;p&gt;Proof of Work (PoW) is a consensus algorithm used by many blockchain networks, including Bitcoin. The central idea behind PoW is to solve a complex mathematical puzzle and easily give out a solution. This mathematical puzzle requires a lot of computational power and thus, the node who solves the puzzle as soon as possible gets to mine the next block.&lt;/p&gt;

&lt;p&gt;In other words, PoW is like a race to solve a puzzle. The first person to solve the puzzle gets to add the next block to the blockchain and receive a reward in the form of cryptocurrency. This process is called mining.&lt;/p&gt;

&lt;p&gt;While PoW is effective at preventing malicious actors from tampering with the blockchain, it has some significant drawbacks. For one, it is very energy-intensive, as nodes must use large amounts of computational power to solve the mathematical puzzle. Additionally, it can be slow and expensive, as transactions must be processed through a complex network of intermediaries.&lt;/p&gt;

&lt;p&gt;Despite these drawbacks, PoW remains one of the most popular consensus mechanisms in blockchain technology.&lt;/p&gt;

&lt;h3&gt;
  
  
  Proof of Stake (PoS)
&lt;/h3&gt;

&lt;p&gt;In Proof of Stake (PoS) consensus algorithm, validators invest in the coins of the system by locking up some of their coins as stakes. After that, all the validators will start validating the blocks. Validators will validate blocks by placing a bet on them if they discover a block that they think can be added to the chain. Based on the actual blocks added in the Blockchain, all the validators get a reward proportionate to their bets, and their stake increase accordingly. In the end, a validator is chosen to generate a new block based on its economic stake in the network. It is used in Ethereum.&lt;/p&gt;

&lt;p&gt;PoS is more energy-efficient, faster and less expensive than PoW because transactions can be processed more quickly and with fewer intermediaries.&lt;/p&gt;

&lt;p&gt;Despite these advantages, PoS has some drawbacks. For one, it can be vulnerable to attacks by malicious actors who hold large amounts of coins in the system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Delegated Proof Of Stake (DPoS)
&lt;/h3&gt;

&lt;p&gt;Delegated Proof of Stake (DPoS) is a consensus mechanism that combines decentralization and efficient decision-making in blockchain networks used by blockchains such as Tron. Token holders vote to elect a fixed number of trusted delegates who validate transactions and add them to the blockchain. These delegates are typically individuals or organizations that have been elected by the community based on their reputation and expertise. This approach improves efficiency by avoiding the energy-intensive competition found in Proof of Work (PoW) systems. DPoS also enables more inclusive governance, allowing users to participate in the network's decision-making process through delegate voting.&lt;/p&gt;

&lt;p&gt;However, DPoS is not without its drawbacks. One concern is that the concentration of power among a limited number of delegates could lead to centralization if a small group gains significant influence. Moreover, voter apathy can result in a lack of participation, reducing the system's overall decentralization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Proof of Authority (PoA)
&lt;/h3&gt;

&lt;p&gt;Proof of Authority (PoA) is a consensus mechanism employed in certain blockchain networks to achieve agreement and validate transactions. It is used in Ethereum Private Networks. Unlike other decentralized systems, PoA relies on a fixed set of pre-approved validators who are known and trusted by the network participants. Validators in a PoA-based blockchain are typically reputable entities or individuals, ensuring a high level of security and governance. Validators take turns to validate and add new blocks to the blockchain based on their authority status. This approach eliminates the need for resource-intensive computations, making PoA highly efficient and eco-friendly.&lt;/p&gt;

&lt;p&gt;However, it introduces centralization, as the system's security relies heavily on the honesty and integrity of the approved validators. Despite this limitation, PoA remains suitable for use cases that prioritize trust and efficiency over full decentralization. Some blockchain projects, especially those with specific governance requirements or private applications, have successfully adopted Proof of Authority as their consensus mechanism.&lt;/p&gt;

&lt;h3&gt;
  
  
  Practical Byzantine Fault Tolerance (PBFT)
&lt;/h3&gt;

&lt;p&gt;Practical Byzantine Fault Tolerance (PBFT) is a consensus mechanism designed to achieve agreement in decentralized networks, even when some participants behave maliciously or experience failures. PBFT is commonly used in permissioned blockchain networks and distributed systems where a fixed set of nodes is known and trusted.&lt;/p&gt;

&lt;p&gt;In a PBFT-based system, consensus is achieved through a series of rounds, where a designated leader proposes a block of transactions. The other nodes then exchange messages to reach agreement on the proposed block. PBFT ensures that, as long as the number of faulty nodes does not exceed a specific threshold (usually one-third of the total nodes), the network can reach consensus and maintain correctness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Proof of capacity (PoC)
&lt;/h3&gt;

&lt;p&gt;Proof of Capacity (PoC) is a unique and eco-friendly consensus mechanism used in some blockchain networks such as Storj, Burst, Chia, and SpaceMint. PoC relies on participants demonstrating their storage capacity, rather than computational power, to compete for the right to add new blocks to the blockchain.&lt;/p&gt;

&lt;p&gt;In a PoC-based blockchain, participants precompute plots or storage spaces with cryptographic data. When a block needs to be added, the network selects a participant whose precomputed plot matches a certain condition, proving their eligibility to create the block. This approach reduces the need for energy-intensive computations, making PoC a greener alternative to Proof of Work (PoW).&lt;/p&gt;

&lt;p&gt;However, PoC has its limitations. The initial setup of precomputed plots can be time-consuming and resource-intensive. Moreover, PoC networks may suffer from centralization if a few participants amass a disproportionately large amount of storage capacity.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Takeaway
&lt;/h3&gt;

&lt;p&gt;Consensus mechanisms have gained crucial significance in the realm of distributed ledgers, databases, and blockchains as our world increasingly embraces digitalization. The future lies in striking a balance between scalability, security, and sustainability while fostering trust and inclusivity. As blockchain permeates industries, selecting the right mechanism becomes vital, setting the stage for a decentralized world of transparency and efficiency, ultimately propelling us towards progress and positive impact.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>beginners</category>
      <category>learning</category>
      <category>web3</category>
    </item>
    <item>
      <title>All About Use Hook In React</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Sun, 30 Jul 2023 08:08:26 +0000</pubDate>
      <link>https://dev.to/oggy107/all-about-use-hook-in-react-1m0g</link>
      <guid>https://dev.to/oggy107/all-about-use-hook-in-react-1m0g</guid>
      <description>&lt;p&gt;React is a popular and widely-used JavaScript library for building user interfaces, enabling developers to create dynamic and interactive web applications efficiently.&lt;/p&gt;

&lt;p&gt;React Hooks, introduced in React 16.8, revolutionized how developers manage stateful logic in functional components. Hooks allow developers to use state and other React features without writing a class, making it easier to organize and reuse logic across components.&lt;/p&gt;

&lt;p&gt;In this article, we will learn about a new react hook named &lt;code&gt;use&lt;/code&gt;, yup that's the name of the hook. This hook is still in experimental stage, If you would like to test it out, make sure your &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; package version is set to "experimental".&lt;/p&gt;

&lt;h2&gt;
  
  
  About &lt;code&gt;use&lt;/code&gt; Hook
&lt;/h2&gt;

&lt;p&gt;The use Hook was revealed back in 2022 by the React team in an RFC (Request For Comments). It was a solution designed to simplify the process of data fetching by reducing the amount of boilerplate code needed to define Promises.&lt;/p&gt;

&lt;p&gt;It can be used like &lt;code&gt;await&lt;/code&gt;. Unlike other Hooks, use Hook has a special trait where it can be called inside conditions, blocks, and loops. This makes it a flexible Hook when you want to add logic and conditional flow without adding more components.&lt;/p&gt;

&lt;p&gt;Ultimately, this hook reduces boiler plate code making code more readable and easy to understand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;This example will show how to use &lt;code&gt;use&lt;/code&gt; hook to reduce the boiler plate code and handle data fetching easily&lt;/p&gt;

&lt;h3&gt;
  
  
  How we fetch data without use hook
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&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;react&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;App&lt;/span&gt; &lt;span class="o"&gt;=&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProduct&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;

    &lt;span class="nf"&gt;useEffect&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="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="s2"&gt;https://xyz.com/products&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;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&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;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&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;product&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using use hook
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;use&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;react&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;getProduct&lt;/span&gt; &lt;span class="o"&gt;=&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="s2"&gt;https://xyz.com/products&lt;/span&gt;&lt;span class="dl"&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;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&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="c1"&gt;// use hook expects promise as argument&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&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;product&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;use&lt;/code&gt; hook eliminated the use of &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useState&lt;/code&gt;, making the code simpler.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the end, React team and community are pushing hard to come up with better solutions for fetching and server components, which means that soon we will have a way simpler solution to control fetch data natively with server components support. Happy coding 👨‍💻&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
    <item>
      <title>4 New ES2023 array methods 🔥</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Fri, 02 Jun 2023 11:56:29 +0000</pubDate>
      <link>https://dev.to/oggy107/4-new-es2023-array-methods-1o99</link>
      <guid>https://dev.to/oggy107/4-new-es2023-array-methods-1o99</guid>
      <description>&lt;p&gt;JavaScript has lots of array methods for doing things like sorting and reversing arrays, but the biggest problem with all these methods is they mutate the array you are working with. This is a huge problem when you are trying to write React code, functional code, or pure functions. This is why I love the new array methods that add immutable versions of all the mutable array methods we are used to. These methods are included in ECMAScript 2023 specification which has been recently finalized. In this article we will take a look at following new array methods&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;toSorted&lt;/li&gt;
&lt;li&gt;toReversed&lt;/li&gt;
&lt;li&gt;toSpliced&lt;/li&gt;
&lt;li&gt;with&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The problem and the hack
&lt;/h2&gt;

&lt;p&gt;One of the best known issues with array methods that mutate the array is when you use them in a React component. You can't mutate an array and then try to set it as a new state because the array itself is the same object and this won't trigger a new render. Instead you need to copy the array first, then mutate the copy and set that as the new state. The hack for this was to create a copy of original array first and then mutate it. 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;const&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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;sortedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sort&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;sortedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['apple', 'banana', 'orange']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;New array methods introduced in ES2023 solve this problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  toSorted
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;toSorted&lt;/code&gt; method returns a new array of sorted elements. It does not mutate the original array unlike its mutable counterpart &lt;code&gt;sorted&lt;/code&gt;.&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;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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;sortedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toSorted&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;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'apple', 'orange']&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;sortedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['apple', 'banana', 'orange']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Know more about &lt;code&gt;toSorted&lt;/code&gt; method &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  toReversed
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;toReversed&lt;/code&gt; method returns a new array contained the elements of original array in reversed order. It does not mutate the original array unlike its mutable counterpart &lt;code&gt;reverse&lt;/code&gt;&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;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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;reversedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toReversed&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;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'apple', 'orange']&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;reversedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['orange', 'apple', 'banana']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Know more about &lt;code&gt;toReversed&lt;/code&gt; method &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  toSpliced
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;toSpliced&lt;/code&gt; method, like &lt;code&gt;splice&lt;/code&gt;, does multiple things at once: it removes the given number of elements from the array, starting at a given index, and then inserts the given elements at the same index. However, it returns a new array instead of modifying the original array. The deleted elements therefore are not returned from this method.&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;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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;splicedFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toSpliced&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dragonfruit&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;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'apple', 'orange']&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;splicedFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'dragonfruit']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Know more about &lt;code&gt;toSpliced&lt;/code&gt; method &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  with
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;with&lt;/code&gt; function is the copy equivalent of using square bracket notation to change one element of an array. The original array is not modified. This allows you to chain array methods while doing manipulations.&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;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&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;newFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dragonfruit&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;fruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'apple', 'orange']&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;newFruits&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ['banana', 'dragonfruit', 'orange']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Know more about &lt;code&gt;with&lt;/code&gt; method &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding 🧑‍💻&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>All About CSS Nesting 🔥</title>
      <dc:creator>Urmalveer Singh</dc:creator>
      <pubDate>Thu, 01 Jun 2023 13:06:21 +0000</pubDate>
      <link>https://dev.to/oggy107/all-about-css-nesting-1o8c</link>
      <guid>https://dev.to/oggy107/all-about-css-nesting-1o8c</guid>
      <description>&lt;p&gt;One of our favorite CSS preprocessor features is now built into the language: &lt;strong&gt;nesting style rules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CSS nesting is a feature that allows you to write CSS rules inside other rules, making your code more organized and readable. It is fairly new and not yet supported by all browsers. You can check the browser compatibility for CSS nesting &lt;a href="https://caniuse.com/?search=css%20nesting"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Following is the preview of HTML elements we will be targeting with CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;I am inside container&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"child_container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;I am inside &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;child&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; container&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Without CSS nesting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;.child_container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;.child_container&lt;/span&gt; &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&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;p&gt;&lt;strong&gt;With CSS nesting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;.child_container&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;span&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F58ynldu7lvm0m3afadi1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F58ynldu7lvm0m3afadi1.png" alt="code output" width="533" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try this in your &lt;a href="https://codepen.io/Urmalveer-Singh/pen/MWPMzxy"&gt;browser&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In above example we are targeting &lt;code&gt;.child_container&lt;/code&gt; class within &lt;code&gt;.container&lt;/code&gt; class using direct child selector &lt;code&gt;&amp;gt;&lt;/code&gt;. This boils down to &lt;code&gt;.container &amp;gt; .child_container&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can clearly see that there is less code repetition when we are using CSS nesting and moreover it makes our code more readable. When we are &lt;em&gt;not&lt;/em&gt; using CSS nesting we need to repeat the complex CSS Selectors again and again to target specific elements and apply different styles to them. CSS nesting solves this issue by using &lt;code&gt;&amp;amp;&lt;/code&gt; symbol which is a reference to parent selector.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding &lt;code&gt;&amp;amp;&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;&amp;amp;&lt;/code&gt; symbol in CSS nesting is a way to reference the parent selector when writing nested rules. It can be used to append or prepend selectors to the parent selector, creating more specific or complex selectors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;.child_container&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;/* .container .child_container */&lt;/span&gt;

        &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;.btn&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
          &lt;span class="c"&gt;/* .container .child_container .btn */&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&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 css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;.content&lt;/span&gt; &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="c"&gt;/* .content .container */&lt;/span&gt;

        &lt;span class="err"&gt;.main&lt;/span&gt; &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
            &lt;span class="c"&gt;/* .main .content .container*/&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nesting &lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It can be very distracting to move to a different area of the stylesheet to find media query conditions that modify a selector and its styles. That distraction is gone with the ability to nest the conditions right inside the context. This bundles all the styles to an element in same place making code more understandable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;@media&lt;/span&gt; &lt;span class="err"&gt;(width&lt;/span&gt; &lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;300px)&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In above example the media query will only affect &lt;code&gt;.container&lt;/code&gt; class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;CSS nesting can also help you with media queries, pseudo-classes, and grouping related styles together. However, you should be careful not to overuse it or create too much specificity, as that can make your code harder to maintain and override&lt;/p&gt;

&lt;p&gt;CSS Nesting is only at version 1. Version 2 will introduce more syntactic sugar and potentially fewer rules to memorize.&lt;/p&gt;

&lt;p&gt;Nesting is a big enhancement to the CSS language. It has authoring implications to almost every architectural aspect of CSS. This big impact needs to be deeply explored and understood before version 2 can effectively be specified.&lt;/p&gt;

&lt;p&gt;You can visit following sites to know more about CSS nesting&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/css-nesting-1/"&gt;https://www.w3.org/TR/css-nesting-1/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.chrome.com/articles/css-nesting/"&gt;https://developer.chrome.com/articles/css-nesting/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy Coding 👨‍💻&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
