<?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: Ryoichi Homma</title>
    <description>The latest articles on DEV Community by Ryoichi Homma (@ryoichihomma).</description>
    <link>https://dev.to/ryoichihomma</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%2F1525883%2F9f90e56e-a081-4364-97c2-e033c4b3768e.png</url>
      <title>DEV Community: Ryoichi Homma</title>
      <link>https://dev.to/ryoichihomma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ryoichihomma"/>
    <language>en</language>
    <item>
      <title>What is a GitHub Gist? Here's Why You Should Use</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Thu, 04 Sep 2025 14:54:05 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/what-is-a-github-gist-heres-why-and-when-you-should-5blp</link>
      <guid>https://dev.to/ryoichihomma/what-is-a-github-gist-heres-why-and-when-you-should-5blp</guid>
      <description>&lt;p&gt;Have you ever wanted to share just a small piece of code, but didn't want to create a whole GitHub repo or share your private repo? &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gist&lt;/strong&gt; is a solution!✨&lt;/p&gt;

&lt;p&gt;I recently had an opportunity to use it for the first time, and I thought it would be helpful to share what it is and when to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is a Gist?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A gist is like a &lt;strong&gt;mini Git repository&lt;/strong&gt; for snippets, configs, or notes. &lt;/li&gt;
&lt;li&gt;It can be &lt;strong&gt;public&lt;/strong&gt; or &lt;strong&gt;secret&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;It supports &lt;strong&gt;version control&lt;/strong&gt; and &lt;strong&gt;forking&lt;/strong&gt;, just like a normal repo. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Why Do We Use a Gist?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Quick and easy sharing (no repo setup needed). &lt;/li&gt;
&lt;li&gt;Lightweight and focused (no extra files or clutter). &lt;/li&gt;
&lt;li&gt;Embeddable in blogs, documentation, Stack Overflow, etc. &lt;/li&gt;
&lt;li&gt;Keeps version history. &lt;/li&gt;
&lt;li&gt;Great for &lt;strong&gt;examples&lt;/strong&gt;, &lt;strong&gt;bug reports&lt;/strong&gt;, &lt;strong&gt;tutorials&lt;/strong&gt;, and &lt;strong&gt;cofigs&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Repo vs. Gist — When to Use What
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use a repo when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're building a full project. &lt;/li&gt;
&lt;li&gt;You need structured collaboration (issues, pull requests, branches). &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Use a gist when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to share just a snippet or a single file. &lt;/li&gt;
&lt;li&gt;You want to share code but don't want to add someone as a repo collaborator. &lt;/li&gt;
&lt;li&gt;You need an easy embeddable example. &lt;/li&gt;
&lt;li&gt;You want something fast and temporary. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Real Scenarios Where Gist Shines
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sharing a &lt;strong&gt;snippet&lt;/strong&gt; with someone outside your private repo. &lt;/li&gt;
&lt;li&gt;Writing a &lt;strong&gt;tutorial/blog&lt;/strong&gt; and embedding example code. &lt;/li&gt;
&lt;li&gt;Submitting a &lt;strong&gt;minimal reproducible example&lt;/strong&gt; when reporting a bug. &lt;/li&gt;
&lt;li&gt;Keep personal &lt;strong&gt;dotfiles&lt;/strong&gt;, &lt;strong&gt;scripts&lt;/strong&gt;, or &lt;strong&gt;cheat sheets&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. How to Share Code with a Gist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://gist.github.com/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;gist.github.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Paste your code snippet in the editor. 

&lt;ul&gt;
&lt;li&gt;You can add a filename with extension (e.g., &lt;code&gt;example.tsx&lt;/code&gt;) for syntax highlighting. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fco9nnn1s25g4nuq7mn2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fco9nnn1s25g4nuq7mn2n.png" alt="gist1" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a description optionally. &lt;/li&gt;
&lt;li&gt;Choose either &lt;strong&gt;public&lt;/strong&gt; or &lt;strong&gt;secret&lt;/strong&gt; gist. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F96rly62rrvkfqoqq9k8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F96rly62rrvkfqoqq9k8d.png" alt="gist2" width="398" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click "&lt;strong&gt;Create public gist&lt;/strong&gt;" or "&lt;strong&gt;Create secret gist&lt;/strong&gt;". &lt;/li&gt;
&lt;li&gt;Share the link. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; You can embed a gist in Markdown by pasting the link directly—it will render as a nice embedded snippet. &lt;/p&gt;

&lt;h2&gt;
  
  
  6. Official Gist Guideline
&lt;/h2&gt;

&lt;p&gt;For more details, check out the official guide, &lt;a href="https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists" rel="noopener noreferrer"&gt;Creating gists&lt;/a&gt;, where you can explore more about gists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Next time you just need to share a snippet, try a gist instead of snipping up a new repo.&lt;/p&gt;

&lt;p&gt;Have you used gists before? &lt;br&gt;
What's your favorite use case? &lt;/p&gt;

&lt;p&gt;👇Please let me know by the comment down below.👇&lt;/p&gt;

</description>
      <category>gist</category>
      <category>github</category>
      <category>git</category>
      <category>versioncontrol</category>
    </item>
    <item>
      <title>Essential Features &amp; Concepts in Frontend You Must Know Before Technical Interviews</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Thu, 04 Sep 2025 07:12:43 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/brushing-up-my-frontend-domain-knowledge-for-job-interview-439l</link>
      <guid>https://dev.to/ryoichihomma/brushing-up-my-frontend-domain-knowledge-for-job-interview-439l</guid>
      <description>&lt;p&gt;As I am preparing for a technical job interview for a frontend engineer position, I have decided to brush up on my frontend domain knowledge by writing this article. &lt;/p&gt;

&lt;h3&gt;
  
  
  Agenda
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;JavaScript Foundational Concepts&lt;/li&gt;
&lt;li&gt;ES5 vs. ES6&lt;/li&gt;
&lt;li&gt;TypeScript vs. JavaScript&lt;/li&gt;
&lt;li&gt;React Features&lt;/li&gt;
&lt;li&gt;Vue Features&lt;/li&gt;
&lt;li&gt;Recommended Resource&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. JavaScript Foundational Concepts:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1.1. DOM Methods
&lt;/h3&gt;

&lt;p&gt;DOM method is an action or function that can be performed on elements within the Document Object Model (DOM) of a web page. The DOM represents the structure of an HTML document as a tree of objects, where each part of the document (like elements, attributes, text) is a node in this tree. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;document.getElementsByTagName()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This method returns a live &lt;code&gt;HTMLCollection&lt;/code&gt; of all child elements with the specified &lt;code&gt;tagName&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;tagName&lt;/code&gt; argument should be a string representing the HTML tag name (e.g., "div", "p", "a", "img"). &lt;/li&gt;
&lt;li&gt;It selects all elements that match the given tag name, regardless of their class or ID.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&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;divs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByTagName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;document.getElementsByClassName()&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;This method returns a live &lt;code&gt;HTMLCollection&lt;/code&gt; of all child elements that have all of the specified &lt;code&gt;className&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;className&lt;/code&gt; argument should be a string representing one or more class names, separated by spaces if multiple classes are targeted (e.g., 'my-class', 'main btn'). &lt;/li&gt;
&lt;li&gt;It selects elements based on their assigned CSS classes.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// select all elements with the class 'highlight'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;highlightedElements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;highlight&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// select all elements with both 'card' and 'active' classes&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;activeCards&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementsByClassName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;card active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1.2. Array Methods
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Array.prototype.**()&lt;/code&gt; is a higher-order array method in JavaScript that provide functional ways to manipulate arrays. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Array.prototype.map()&lt;/code&gt; creates a new array by applying a provided function to each element in the calling array. The new array will have the same length as the original array, but its elements will be the results of the callback function. It is used for transforming each element of an array.
&lt;/li&gt;
&lt;/ul&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;nums&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&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;doubleNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// return [2, 4, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Array.prototype.filter()&lt;/code&gt; creates a new array containing only the elements for which the provided callback function returns a truthy value. It is used for selecting a subset of elements from an array based on a condition. The new array's length may be less than or equal to the original array's length.
&lt;/li&gt;
&lt;/ul&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;nums&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&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="mi"&gt;5&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;oddNums&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&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="c1"&gt;// return [1, 3, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Array.prototype.reduce()&lt;/code&gt; executes a reducer callback function on each element of the array, resulting in a single output value. This value can be a number, a string, an object, an array, or any other type. It is used for accumulating a single value from an array. It takes an optional &lt;code&gt;initialValue&lt;/code&gt; for the accumulator.
&lt;/li&gt;
&lt;/ul&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;nums&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&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="mi"&gt;5&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;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;current&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;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;current&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="c1"&gt;// return 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;map&lt;/code&gt; is for transforming (one-to-one mapping of elements). &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filter&lt;/code&gt; is for selection (creating a subset based on a condition). &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reduce&lt;/code&gt; is for aggregation (reducing an array to a single value).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1.3. &lt;code&gt;==&lt;/code&gt; vs. &lt;code&gt;===&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;==&lt;/code&gt; &lt;strong&gt;(Abstract Equality):&lt;/strong&gt; this operator compares values for equality after performing &lt;strong&gt;type coercion&lt;/strong&gt;. If the two operands are different types, JavaScript will try to convert one or both operands to a common type before making the comparison. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;===&lt;/code&gt; &lt;strong&gt;(Strict Equality):&lt;/strong&gt; this operator compares both the &lt;strong&gt;value and the type&lt;/strong&gt; of the operands. No type coercion is performed. For the comparison to be true, both the value and the data type must be identical. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For reliable and predictable code, it's a best practice to use the strict equality operator (&lt;code&gt;===&lt;/code&gt;) as it prevents unexpected behavior from implicit type conversions. &lt;/p&gt;

&lt;h3&gt;
  
  
  1.4. Bearer
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Bearer&lt;/code&gt; is used in the &lt;strong&gt;Authorization&lt;/strong&gt; header to specify the type of token being sent in the &lt;strong&gt;Authentication header&lt;/strong&gt; for authentication. It tells the server that the value following &lt;code&gt;Bearer&lt;/code&gt; is a bearer token, which is a security token granting access to protected resources. &lt;/p&gt;

&lt;h4&gt;
  
  
  How the &lt;code&gt;Bearer&lt;/code&gt; is beneficial
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Standardized Authentication:&lt;/strong&gt; &lt;code&gt;Bearer&lt;/code&gt; tokens are widely used in APIs for secure, stateless authentication. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity:&lt;/strong&gt; the client only needs to include the token; the server validates it without extra steps. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; tokens can be short-lived and easily revoked, reducing risk if compromised. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;br&gt;
Using &lt;code&gt;Bearer&lt;/code&gt; makes authentication secure, simple, and compatible with modern API standards. &lt;/p&gt;
&lt;h2&gt;
  
  
  2. ES5 vs. ES6:
&lt;/h2&gt;

&lt;p&gt;ES6 introduced numerous new features and syntax enhancements aimed at making JavaScript development more efficient, readable, and maintainable compared to ES5.&lt;/p&gt;
&lt;h3&gt;
  
  
  2.1. Key Differences
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Variable Declarations:&lt;/strong&gt; ES5 primarily used 'var' for variable declarations, which have function-level scope. ES6 introduced &lt;code&gt;let&lt;/code&gt; for block-scoped variables and &lt;code&gt;const&lt;/code&gt; for block-scoped constant variables, improving scope management and preventing accidental reassignments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; is the old way of declaring variables. &lt;code&gt;var&lt;/code&gt; declarations are &lt;strong&gt;function-scoped&lt;/strong&gt; and can be re-declared and re-assigned. This can lead to unexpected behavior and is generally avoided in modern development. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; declarations are &lt;strong&gt;block-scoped&lt;/strong&gt;. This means a variable declared with &lt;code&gt;let&lt;/code&gt; is only accessible within the block of code (e.g., inside &lt;code&gt;{}&lt;/code&gt;) it was defined in. You can re-assign a &lt;code&gt;let&lt;/code&gt; variable, but you cannot re-declare it in the same scope. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt; is for declaring variables that are &lt;strong&gt;block-scoped&lt;/strong&gt; and cannot be re-assigned. The value must be initialized at the time of declaration. While the variables themselves can't be re-assigned, if the value is an object or array, its properties or elements can still be mutated. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Arrow Functions:&lt;/strong&gt; ES6 introduced arrow functions, providing a more concise syntax for writing function expressions and handling &lt;code&gt;this&lt;/code&gt; context more predictably. ES5 relied on traditional &lt;code&gt;function&lt;/code&gt; keyword syntax.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Classes:&lt;/strong&gt; ES6 introduced the &lt;code&gt;class&lt;/code&gt; keyword, offering a more familiar and structured syntax for defining object-oriented structures, similar to other object-oriented languages. ES5 simulated class-like behavior using constructor functions and prototypes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Promises:&lt;/strong&gt; ES6 introduced &lt;code&gt;Promises&lt;/code&gt; for handling asynchronous operations, providing a cleaner and more structured approach compared to the callback-based approach, often leading to "callback hell" in ES5. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  2.2. Promise vs. async/await
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Promises
&lt;/h4&gt;

&lt;p&gt;Promises are objects that represent the result of asynchronous processing and its value, whether the process succeeded (resolved) or failed (rejected). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pending:&lt;/strong&gt; this initial state; the operation has not yet completed. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fulfilled:&lt;/strong&gt; the operation completed successfully. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rejected:&lt;/strong&gt; the operation failed. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You chain &lt;code&gt;.then()&lt;/code&gt; and &lt;code&gt;.catch()&lt;/code&gt; methods to a Promise to handle the successful and failed outcomes, respectively.&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&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="o"&gt;=&amp;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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Network response was not okay&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="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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;There was a problem with the fetch operation:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Promise.all()&lt;/code&gt; is used to wait for all promises to be completed. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Promise.any()&lt;/code&gt; is used to return a resolved (succeeded) value once any of the initial promises is resolved (succeeded).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  async/await
&lt;/h4&gt;

&lt;p&gt;The async/await is a modern JS feature that provides a cleaner, more readable way to work with Promises.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;async&lt;/code&gt; is used to declare an asynchronous function. This function automatically returns a Promise. &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;await&lt;/code&gt; is used inside an &lt;code&gt;async&lt;/code&gt; function to &lt;strong&gt;pause the execution&lt;/strong&gt; of the function until the Promise it's waiting on is settled (either fulfilled or rejected). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Error handling with &lt;code&gt;async/await&lt;/code&gt; is done using a traditional &lt;code&gt;try...catch&lt;/code&gt; block, which is familiar to developers from synchronous code.&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&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;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Network response was not okay&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;There was a problem with the fetch operation:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 

&lt;span class="nf"&gt;fetchData&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;Summary&lt;/strong&gt; &lt;br&gt;
&lt;code&gt;async/await&lt;/code&gt; doesn't replace Promises; it provides a &lt;strong&gt;more intuitive and powerful way to use them&lt;/strong&gt;. It's the preferred method for handling modern asynchronous JavaScript, as it makes the code much cleaner and easier to read.  &lt;/p&gt;
&lt;h3&gt;
  
  
  2.3 Why do we need asynchronous functions?
&lt;/h3&gt;

&lt;p&gt;We need asynchronous functions to perform operations that take time without blocking the main program threads. This is crucial for maintaining a responsive user experience, especially in applications that handle tasks like fetching data from a server, reading a file from the disk, or executing a long-running calculation. &lt;/p&gt;
&lt;h4&gt;
  
  
  Problem with synchronous code
&lt;/h4&gt;

&lt;p&gt;In a &lt;strong&gt;synchronous&lt;/strong&gt; programming mode, code is executed line by line. That is, when a function or operation is called, the program &lt;strong&gt;waits&lt;/strong&gt; for it to complete before moving to the next line. If a long-running task is initiated, the entire program becomes unresponsive. For a web browser, this means the user interface freezes—the user can't click buttons, type in a field, or see animations. &lt;/p&gt;
&lt;h4&gt;
  
  
  Solution: asynchronous functions
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous&lt;/strong&gt; functions allow the program to initiate a task and &lt;strong&gt;continue executing other code&lt;/strong&gt; without waiting for the task to finish. The program is notified once the task is complete, at which point it can handle the result. This non-blocking behavior is essential for modern applications. &lt;/p&gt;
&lt;h2&gt;
  
  
  3. TypeScript vs. JavaScript:
&lt;/h2&gt;

&lt;p&gt;TypeScript (TS) is a superset of JavaScript (JS) that adds &lt;strong&gt;static typing&lt;/strong&gt; to the language. This means you can define the types of variables, function parameters, and return values, which helps catch errors during development rather than at runtime. JS, on the other hand, is a &lt;strong&gt;dynamically typed&lt;/strong&gt; language, which means type checking happens only when the code is executed. &lt;/p&gt;
&lt;h3&gt;
  
  
  3.1. Why Choose TypeScript?
&lt;/h3&gt;

&lt;p&gt;TS is particularly valuable for large, complex, or long-term projects. The static typing provides a safety net that helps prevent a common class of bugs. It also makes the code more self-documenting, as the type definitions can explain what kind of data a function expects and returns. Many popular frameworks and libraries were built with TS, and it is widely used in enterprise-level applications. &lt;/p&gt;
&lt;h3&gt;
  
  
  3.2. Type Interface
&lt;/h3&gt;

&lt;p&gt;In TypeScript, a &lt;strong&gt;type interface&lt;/strong&gt; refers to an &lt;strong&gt;interface declaration&lt;/strong&gt;, which is used to define the shape or structure of an object, specifying the properties and methods that an object must have. &lt;/p&gt;
&lt;h4&gt;
  
  
  Why the interfaces are useful
&lt;/h4&gt;

&lt;p&gt;Interfaces are a powerful tool for ensuring code consistency and safety. They help enforce that any object you use in a specific context has a predictable shape. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type Checking:&lt;/strong&gt; the compiler uses interfaces to check if an object conforms to the defined structure at compile-time. If it doesn't, you get an immediate error, preventing a common class of bugs. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Documentation:&lt;/strong&gt; an interface acts as a form of self-documentation. Other developers can look at an interface and immediately understand what an object is supposed to look like. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Predictability and Autocomplete:&lt;/strong&gt; when your IDE knows the structure of an object through an interface, it can offer smart code completion and helpful suggestions, making development faster and less prone to typos. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  How the interface works
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// 1. Define the interface&lt;/span&gt;
&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;email&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// The '?' makes this property optional&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Use the interface to define a variable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;1&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;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;alice@example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// 3. This would cause a compile-time error because 'id' is missing&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bob@example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this example, the &lt;code&gt;User&lt;/code&gt; interface dictates that any object of type &lt;code&gt;User&lt;/code&gt; &lt;strong&gt;must&lt;/strong&gt; have a &lt;code&gt;number&lt;/code&gt; called &lt;code&gt;id&lt;/code&gt; and a &lt;code&gt;string&lt;/code&gt; called &lt;code&gt;name&lt;/code&gt;. If you try to create an object that doesn't meet this contract, the TypeScript compiler will immediately flag an error.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. React Features:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  4.1. Prop Drilling
&lt;/h3&gt;

&lt;p&gt;Prop drilling is a term used in component-based frameworks like React to describe the process of passing data from a parent component down to a deeply nested child component. &lt;/p&gt;
&lt;h4&gt;
  
  
  How prop drilling works
&lt;/h4&gt;

&lt;p&gt;Imagine you have a component tree like this: &lt;br&gt;
&lt;code&gt;App&lt;/code&gt; -&amp;gt; &lt;code&gt;ParentComponent&lt;/code&gt; -&amp;gt; &lt;code&gt;ChildComponent&lt;/code&gt; -&amp;gt; &lt;code&gt;GrandchildComponent&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Suppose the &lt;code&gt;App&lt;/code&gt; component holds a piece of data like a username that is only needed by the &lt;code&gt;GrandchildComponent&lt;/code&gt;. To get the username from the &lt;code&gt;App&lt;/code&gt; component to the &lt;code&gt;GrandchildComponent&lt;/code&gt;, you have to &lt;strong&gt;drill&lt;/strong&gt; it down through the intermediate components. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;App&lt;/code&gt; passes the &lt;code&gt;user&lt;/code&gt; prop to &lt;code&gt;ParentComponent&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ParentComponent&lt;/code&gt; receives the &lt;code&gt;user&lt;/code&gt; prop, but doesn't use it. It simply passes it on to &lt;code&gt;ChildComponent&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ChildComponent&lt;/code&gt; also receives the &lt;code&gt;user&lt;/code&gt; prop and doesn't use it again. It passes it on to &lt;code&gt;GrandchildComponent&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Finally, &lt;code&gt;GrandchildComponent&lt;/code&gt; receives the &lt;code&gt;user&lt;/code&gt; prop and uses it to display the username.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  4.2. Props vs. State
&lt;/h3&gt;

&lt;p&gt;In React, &lt;strong&gt;props&lt;/strong&gt; are data passed from a parent component to a child component, acting as read-only arguments, while &lt;strong&gt;state&lt;/strong&gt; is data managed internally by a component that can change over time, triggering a re-render. &lt;strong&gt;Props&lt;/strong&gt; provide data to customize child components, whereas &lt;strong&gt;state&lt;/strong&gt; allows a component to manage its own local, dynamic information, such as user inputs or API data. &lt;/p&gt;
&lt;h3&gt;
  
  
  4.3. Virtual DOM
&lt;/h3&gt;

&lt;p&gt;The Virtual DOM (VDOM) is a lightweight, in-memory representation of the real DOM (Document Object Model). It's a key concept in frameworks like React that helps optimize performance. &lt;/p&gt;
&lt;h4&gt;
  
  
  How VDOM improves performance in frameworks
&lt;/h4&gt;

&lt;p&gt;Instead of directly manipulating the real DOM, React first makes changes to the VDOM. When the state of a component updates, React creates a new VDOM tree and compares it to the previous one in a process called &lt;strong&gt;diffing&lt;/strong&gt;. It calculates the minimal number of changes needed to sync the real DOM with the new VDOM. Finally, it batches these changes and updates the real DOM only where necessary. &lt;/p&gt;

&lt;p&gt;This approach is faster because: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Manipulating a JS object (the DOM) in memory is significantly quicker than directly interacting with the browser's DOM. &lt;/li&gt;
&lt;li&gt;It reduces the number of costly DOM manipulations, as only the changed parts of the UI are updated.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  4.4. React Hooks
&lt;/h3&gt;

&lt;p&gt;React hooks are functions that allow "hooking into" React state and lifecycle features from functional components. They enable the use of state and other React features in functional components, which previously were only available in class components. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;useState()&lt;/strong&gt;: the &lt;code&gt;useState()&lt;/code&gt; hook allows functional components to manage and update state. It is fundamental for creating interactive and dynamic user interfaces. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;useRef()&lt;/strong&gt;: the &lt;code&gt;useRef()&lt;/code&gt; hook allows the creation of a mutable reference object that persists across component re-renders without causing the component to re-render when its value changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  5. Vue Features:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  5.1. Ref Function
&lt;/h3&gt;

&lt;p&gt;In Vue.js, a &lt;strong&gt;reactive reference&lt;/strong&gt; refers to a value that any changes are made to this value automatically trigger updates in the UI. The primary way to create such a reference is using the &lt;code&gt;ref&lt;/code&gt; function. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ref&lt;/code&gt; is used to create a reactive reference to a single value. This value can be a primitive type (like string, number, or boolean) or an object/array. &lt;/li&gt;
&lt;li&gt;When you create a reactive reference with &lt;code&gt;ref&lt;/code&gt;, Vue wraps the value in a special object that allows it to detect changes. &lt;/li&gt;
&lt;li&gt;To access or modify the actual value held by a &lt;code&gt;ref&lt;/code&gt;, you must use the &lt;code&gt;.value&lt;/code&gt; property (&lt;code&gt;username.value = newValue&lt;/code&gt;). &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5.2. &lt;code&gt;v-model&lt;/code&gt; Directive
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;v-model&lt;/code&gt; directive in Vue.js is a fundamental feature that enables two-way data binding. It simplifies the synchronization of data between a component's state and form input elements. &lt;br&gt;
For example, when it comes to &lt;strong&gt;two-way data binding&lt;/strong&gt;, &lt;code&gt;v-model&lt;/code&gt; automatically handles both updating the UI when the data changes and updating the data when the UI element like an input field is modified. &lt;/p&gt;
&lt;h3&gt;
  
  
  5.3. &lt;code&gt;defineEmits()&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In Vue 3, &lt;code&gt;defineEmits()&lt;/code&gt; is a compiler macro used to declare the custom events that a component can emit (the mechanism by which a child component sends a custom event and optionally data to its parent component). It serves as a way to explicitly define the interface for a component's outgoing communication, making it clearer what events a parent component can listen for. &lt;/p&gt;
&lt;h4&gt;
  
  
  How emit and &lt;code&gt;defineEmits()&lt;/code&gt; works
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When you call &lt;code&gt;emit('event-name')&lt;/code&gt;, it triggers the &lt;code&gt;event-name&lt;/code&gt; event. &lt;/li&gt;
&lt;li&gt;The parent component listens for this event (e.g., &lt;code&gt;@event-name="passwordWasSet = true"&lt;/code&gt;) and can react, such as showing a success message or changing the UI state. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  5.4. &lt;code&gt;computed&lt;/code&gt; Property
&lt;/h3&gt;

&lt;p&gt;In Vue.js, &lt;code&gt;computed&lt;/code&gt; properties play a crucial role in password validation by providing a reactive, efficient way to derive validation states or messages based on other reactive data, such as the password input itself. &lt;/p&gt;
&lt;h4&gt;
  
  
  How &lt;code&gt;computed&lt;/code&gt; works in password validation
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deriving Validation Status:&lt;/strong&gt; you define a &lt;code&gt;computed&lt;/code&gt; property that returns a boolean indicating whether the password meets certain criteria (e.g., &lt;code&gt;isPasswordValid&lt;/code&gt;, &lt;code&gt;passwordMatch&lt;/code&gt;).
&lt;/li&gt;
&lt;/ul&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;defineComponent&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;vue&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;defineComponent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nf"&gt;data&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;passwordConfirm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;passwordMatch&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordConfirm&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&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;&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="p"&gt;},&lt;/span&gt;
    &lt;span class="nf"&gt;isPasswordStrong&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Example password strength rule:&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&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;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  5.5. &lt;code&gt;v-if&lt;/code&gt; and &lt;code&gt;v-for&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;v-if&lt;/code&gt;: Conditionally renders an element or block. If the condition is &lt;code&gt;true&lt;/code&gt;, the element or block is rendered to the DOM; if &lt;code&gt;false&lt;/code&gt;, it is removed. This is useful for showing or hiding UI parts based on states (like error messages). &lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Conjunction with &lt;code&gt;v-else-if&lt;/code&gt; and &lt;code&gt;v-else&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;It can be used in conjunction with &lt;code&gt;v-else-if&lt;/code&gt; and &lt;code&gt;v-else&lt;/code&gt; to create conditional blocks similar to &lt;code&gt;if/else if/else&lt;/code&gt; statements in programming.&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;p&lt;/span&gt; &lt;span class="na"&gt;v-if=&lt;/span&gt;&lt;span class="s"&gt;"isVisible"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This paragraph is conditionally rendered.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-else-if=&lt;/span&gt;&lt;span class="s"&gt;"isSecondary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is a secondary condition.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;v-else&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is the fallback.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;v-for&lt;/code&gt;: Renders a list of elements by iterating over an array or object. For each item, it creates a new DOM. This is useful for displaying dynamic lists such as password criteria or error messages. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Key attribute
&lt;/h4&gt;

&lt;p&gt;When using &lt;code&gt;v-for&lt;/code&gt;, it is recommended to provide a unique &lt;code&gt;key&lt;/code&gt; attribute to each iterated element for efficient list updates.&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;ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"item in items"&lt;/span&gt; &lt;span class="na"&gt;:key=&lt;/span&gt;&lt;span class="s"&gt;"item.id"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    {{ item.name }}
  &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.6. &lt;code&gt;aria-invalid&lt;/code&gt; Attribute
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;aria-invalid&lt;/code&gt; is an ARIA (Accessible Rich Internet Applications) attribute used to indicate that the entered value is invalid.&lt;/p&gt;

&lt;h4&gt;
  
  
  How the &lt;code&gt;aria-invalid&lt;/code&gt; attribute works
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;aria-invalid="true"&lt;/code&gt; is present on an input, screen readers will announce that the field is invalid, helping users understand which fields require correction. &lt;/li&gt;
&lt;li&gt;If omitted or set to &lt;code&gt;false&lt;/code&gt;, the field is considered valid.
&lt;/li&gt;
&lt;/ul&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;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;aria-invalid=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"email-error-message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Please enter a valid email address.&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Recommended Resource:
&lt;/h2&gt;

&lt;p&gt;With refreshing my frontend domain knowledge at this time, I came across a really convenient resource called &lt;a href="https://www.greatfrontend.com/?utm_source=frontendinterviewhandbook&amp;amp;utm_medium=referral&amp;amp;utm_content=banner&amp;amp;gnrs=frontendinterviewhandbook" rel="noopener noreferrer"&gt;GreatFrontEnd&lt;/a&gt;. I highly recommend it not only for those who are preparing for technical interviews but also for anyone just starting their frontend journey, as it's a well-structured guide that highlights the essential features and concepts to before stepping into a professional role. &lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Mastering the fundamentals of JavaScript, TypeScript, React, and Vue gives you the confidence to tackle both interviews and real-world projects. From understanding async code to handling props, refs, and computed values, these core skills are the backbone of modern frontend engineering. Keep practicing, stay curious, and you’ll keep leveling up as a developer. &lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>technicalinterview</category>
    </item>
    <item>
      <title>DSA &amp; Searching Methods: Refresher for Coding Interview</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Fri, 16 May 2025 05:50:43 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/dsa-searching-methods-refresher-for-coding-interview-3bcp</link>
      <guid>https://dev.to/ryoichihomma/dsa-searching-methods-refresher-for-coding-interview-3bcp</guid>
      <description>&lt;p&gt;Since I prepare for upcoming coding interviews, I've decided to revisit the core concepts of Data Structures and Algorithms (DSA). This article will be the second refresher to me where I'll explain searching methods for DSA. Whether you're revising for interviews or brushing up on your fundamentals, I hope you find this helpful!&lt;/p&gt;

&lt;h2&gt;
  
  
  Searching Methods
&lt;/h2&gt;

&lt;p&gt;Searching is about finding the required data in a structure. Here are the most common search algorithms. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Linear Search
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; traverse the list one element at a time. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; unsorted arrays, small data sets.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&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="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;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&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;===&lt;/span&gt; &lt;span class="nx"&gt;target&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;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="k"&gt;return&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="p"&gt;}&lt;/span&gt; 

&lt;span class="c1"&gt;// return 1 because 5 can be found in array at the index of 1.&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="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 

&lt;span class="c1"&gt;// return 0 because 3 can be found in array at the index of 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="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 

&lt;span class="c1"&gt;// return -1 because 0 cannot be found in array.&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="nf"&gt;linearSearch&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Binary Search (Iterative)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; divide the sorted list into half to find the element. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(log n)&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; efficient lookup in sorted collections.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Array must be sorted.&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;function&lt;/span&gt; &lt;span class="nf"&gt;binarySearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;target&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;left&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;right&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;mid&lt;/span&gt; &lt;span class="o"&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;floor&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&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;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;target&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;mid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mid&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="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="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="p"&gt;}&lt;/span&gt; 

&lt;span class="c1"&gt;// return 3 because 7 can be found in array at the index of 3. &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="nf"&gt;binarySearch&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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// return -1 because 0 cannot be found in array. &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="nf"&gt;binarySearch&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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&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="c1"&gt;// return 0 because 1 can be found in array at the index of 1. &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="nf"&gt;binarySearch&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;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Depth-First Search (DFS)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; explores as deep as possible along a branch before backtracking. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(V + E)&lt;/code&gt; (vertices + edges). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; graphs, trees, maze solving, topological sort.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;visited&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="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;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&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="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&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;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// current node&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;neighbor&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;graph&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="nx"&gt;node&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;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;neighbor&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nf"&gt;dfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;neighbor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;visited&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Breadth-First Search (BFS)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; explores all neighbors before going deeper. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(V + E)&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Used Case:&lt;/strong&gt; shortest path in unweighted graphs, level-order tree traversal.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&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;visited&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 

  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;queue&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;&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="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// take out from queue&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;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&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="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// current node&lt;/span&gt;
      &lt;span class="nx"&gt;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&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;neighbor&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;graph&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="nx"&gt;node&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;visited&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;neighbor&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;queue&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;neighbor&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Binary Search Tree Search
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; traverse the BST left or right depending on the value. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(log n)&lt;/code&gt; average, &lt;code&gt;O(n)&lt;/code&gt; worst (unbalanced tree). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; dynamic sets, range queries.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;searchBST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&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="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;node&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&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="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;node&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// if found&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;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;node&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;searchBST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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="c1"&gt;// let smaller node to be left&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;searchBST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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="c1"&gt;// let bigger node to be right&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;
  
  
  6. Hash-Based Search
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; use a hash function to find the index. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time Complexity:&lt;/strong&gt; &lt;code&gt;O(1)&lt;/code&gt; average. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; fast key-value lookup, duplicates detection.
&lt;/li&gt;
&lt;/ul&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;map&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;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;map&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="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="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;map&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="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="mi"&gt;5&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;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Found&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;map&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="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="c1"&gt;// return 10&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Not Found&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Upcoming Posts
&lt;/h2&gt;

&lt;p&gt;This article refreshes my DSA knowledge. In upcoming posts, I'll explore sorting algorithms in more details.&lt;br&gt;
If you're also preparing for coding interviews or learning DSA, follow for more practical and concise DSA content. Feel free to leave comments for any questions!&lt;/p&gt;

</description>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>dsa</category>
      <category>searchingmethods</category>
    </item>
    <item>
      <title>Data Structures &amp; Algorithms: Refresher for Coding Interview</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Wed, 14 May 2025 09:01:36 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/data-structures-refresher-for-coding-interview-434h</link>
      <guid>https://dev.to/ryoichihomma/data-structures-refresher-for-coding-interview-434h</guid>
      <description>&lt;p&gt;Since I prepare for upcoming coding interviews, I've decided to revisit the core concepts of Data Structures and Algorithms (DSA). This article will be the first refresher to me where I'll explain essential data structures in a straightforward way. Whether you're revising for interviews or brushing up on your fundamentals, I hope you find this helpful!&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Data Structures
&lt;/h2&gt;

&lt;p&gt;Understanding data structures is essential because choosing the right one directly impacts the efficiency of your solution. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Array
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; a collection of elements stored in contiguous memory locations. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Time:&lt;/strong&gt; &lt;code&gt;O(1)&lt;/code&gt; for random access. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; static data storage, lookup tables, buffers.
&lt;/li&gt;
&lt;/ul&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;3&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="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;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// return 3&lt;/span&gt;
&lt;span class="nx"&gt;arr&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="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// add 5 at the end&lt;/span&gt;
&lt;span class="nx"&gt;arr&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;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="c1"&gt;// remove elements from index of 1 to 2; return [ 1, 4, 5 ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Linked List
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; a linear collection where each element points to the next. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type:&lt;/strong&gt; Singly, Doubly, and Circular Linked Lists. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Time:&lt;/strong&gt; &lt;code&gt;O(n)&lt;/code&gt; for search; efficient insertions/deletions at the beginning. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; dynamic memory allocation, real-time data streams.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LinkedList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="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;val&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;node&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;Node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&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;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
      &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&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;print&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;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;head&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; -&amp;gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
      &lt;span class="nx"&gt;curr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&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="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;null&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="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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LinkedList&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;push&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="nx"&gt;list&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="mi"&gt;2&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;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&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;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// return 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; null&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Stack (LIFO)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; follows Last-In-First-Out (LIFO) principle. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operations:&lt;/strong&gt; &lt;code&gt;push()&lt;/code&gt;, &lt;code&gt;pop()&lt;/code&gt;, &lt;code&gt;peak()&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; undo functionality, expression evaluation, backtracking.
&lt;/li&gt;
&lt;/ul&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;stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; 
&lt;span class="nx"&gt;stack&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="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="mi"&gt;3&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="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;stack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// return 4 &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;stack&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// return [1, 2, 3] &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Queue (FIFO)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; follows First-In-First-Out (FIFO) principle. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variants:&lt;/strong&gt; Circular Queue, Priority Queue, Deque. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; task scheduling, BFS traversal, data buffering.
&lt;/li&gt;
&lt;/ul&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;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; 
&lt;span class="nx"&gt;queue&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&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="mi"&gt;5&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;queue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// return [1, 3, 4, 5]&lt;/span&gt;
&lt;span class="nx"&gt;queue&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="mi"&gt;2&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;queue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// return [1, 3, 4, 5, 2]&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;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// return 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Hash Table / Hash Map
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; key-value pairs with constant-time average access. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operations:&lt;/strong&gt; &lt;code&gt;insert()&lt;/code&gt;, &lt;code&gt;delete()&lt;/code&gt;, &lt;code&gt;search()&lt;/code&gt; in &lt;code&gt;O(1)&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case:&lt;/strong&gt; caching, frequency counting, fast lookup.
&lt;/li&gt;
&lt;/ul&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;map&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;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;map&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&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="nx"&gt;map&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;'&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="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;map&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;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// return 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Tree
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; hierarchical data structure with nodes and children. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type:&lt;/strong&gt; 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Binary Tree&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Binary Search Tree (BST)&lt;/strong&gt;: Left &amp;lt; Node &amp;lt; Right&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heap&lt;/strong&gt;: Min-Heap / Max-Heap &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trie&lt;/strong&gt;: Prefix tree for strings&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Use Case:&lt;/strong&gt; Hierarchical storage (e.g., file systems), autocomplete, heap sort.
&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Binary Search Tree&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TreeNode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&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="nx"&gt;newVal&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&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;TreeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;right&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;TreeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&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;root&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;TreeNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fvsw6gclew6qnlcn42i8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvsw6gclew6qnlcn42i8k.png" alt="BST" width="173" height="142"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Graph
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; set of nodes (vertices) connected by edges. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type:&lt;/strong&gt; directed, undirected, weighted, unweighted, cyclic, acyclic. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case&lt;/strong&gt;: social networks, pathfinding (Dijkstra Algorithm), dependency resolution.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Adjacency List&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Graph&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adjList&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;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;addVertex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adjList&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="nx"&gt;v&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;w&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adjList&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="nx"&gt;w&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;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undirected graph&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;  

  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adjList&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;`{key} -&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&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="s2"&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;graph&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;Graph&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addVertex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addVertex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="c1"&gt;// A -&amp;gt; B&lt;/span&gt;
&lt;span class="c1"&gt;// B -&amp;gt; A&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Upcoming Posts
&lt;/h2&gt;

&lt;p&gt;This article serves as a refresher for my DSA journey. In upcoming posts, I'll dive deeper into searching methods. &lt;br&gt;
If you're also preparing for coding interviews or learning DSA, follow for more practical and concise DSA content. Feel free to leave comments for any questions!&lt;/p&gt;

</description>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>dsa</category>
      <category>codinginterview</category>
    </item>
    <item>
      <title>How to Integrate an AWS EC2 Instance with VS Code using Remote SSH</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Sun, 23 Feb 2025 05:02:52 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/how-to-integrate-ec2-server-with-vs-code-using-remote-ssh-1cpk</link>
      <guid>https://dev.to/ryoichihomma/how-to-integrate-ec2-server-with-vs-code-using-remote-ssh-1cpk</guid>
      <description>&lt;p&gt;Developing directly on Amazon EC2 instance can improve workflow efficiency and eliminate the need for constant file transfers. This article will explain how to integrate an EC2 instance with VS Code using the Remote - SSH extension. &lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;AWS EC2 instance running &lt;/li&gt;
&lt;li&gt;SSH access to your EC2 instance&lt;/li&gt;
&lt;li&gt;VS Code installed on your local machine &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Install VS Code Extension
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9266mwcsjdxoq862239m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9266mwcsjdxoq862239m.png" alt="Remote SSH" width="800" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Connect to EC2 via SSH in VS Code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Press &lt;code&gt;shift + ctrl + P&lt;/code&gt; at the same time, and select &lt;code&gt;Remote SSH: Connect to Host&lt;/code&gt;. &lt;br&gt;
&lt;a href="https://media2.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%2F286btzxuyjsvq4p6f89z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F286btzxuyjsvq4p6f89z.png" alt="Step1" width="800" height="136"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;code&gt;+ Add New SSH Host...&lt;/code&gt;, type the following and press &lt;code&gt;enter&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ec2-user@XX.XX.XX.XX 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F9quub11i1q5q4qp2r8xl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9quub11i1q5q4qp2r8xl.png" alt="Step2" width="800" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the top one, &lt;code&gt;.ssh\config&lt;/code&gt; to open the config file and add the following:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Host ec2-server
  HostName XX.XX.XX.XX
  User ec2-user
  IdentityFile ~/ec2
  ForwardAgent yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Open the &lt;strong&gt;Remote Explore&lt;/strong&gt; tab on the left sidebar. &lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;SSH Targets&lt;/strong&gt;, locate &lt;code&gt;ec2-server&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;connect arrow&lt;/strong&gt; (→). &lt;/li&gt;
&lt;li&gt;Select the correct OS for the remote machine. &lt;/li&gt;
&lt;li&gt;If &lt;code&gt;SSH: ec2-server&lt;/code&gt; appears at the bottom left and the terminal shows something like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ec2-user@ip-xx-xx-xx-xx ~]$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have successfully connected to the remote EC2 instance. &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Transfer Project Folder
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Simply drag and drop your project folder to the root directory of the EC2 instance. 
&lt;img src="https://media2.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%2F3lwnx5pptd3ditctw4rf.png" alt="Root directory" width="438" height="277"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these steps, you should be able to integrate the EC2 instance with VS Code. This setup improves development efficiency and allows seamless remote coding in a cloud environment. &lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>ssh</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Understanding Digest Authentication</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Wed, 19 Feb 2025 22:28:25 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/understanding-digest-authentication-2oc5</link>
      <guid>https://dev.to/ryoichihomma/understanding-digest-authentication-2oc5</guid>
      <description>&lt;p&gt;This article is an extended version of my last article, &lt;a href="https://dev.to/ryoichihomma/basic-vs-digest-authentication-56hn"&gt;Understanding Basic Authentication&lt;/a&gt;, exploring more about Digest Authentication, especially how it works, how to implement it, and the differences between Basic and Digest Authentications. &lt;/p&gt;

&lt;h2&gt;
  
  
  Digest Authentication
&lt;/h2&gt;

&lt;p&gt;Digest Authentication is a more secure alternative to Basic Authentication. Instead of sending the credentials in plaintext (Base64), it uses MD5 hashing along with a challenge-response mechanism. This prevents passwords from being directly intercepted, making it more secure than Basic Authentication. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Follow these steps to implement Digest Authentication on the Apache server: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Apache using yum command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo install httpd -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a protected directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir -p /var/www/html/digest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;/digest&lt;/code&gt; can be anything. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the Digest password file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo htdigest -c /etc/httpd/conf.d/.digestpass "Digest Auth" username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Ener and confirm the password. &lt;/li&gt;
&lt;li&gt;The &lt;code&gt;AuthName&lt;/code&gt; value must match the Apache configuration ("Digest Auth" in this case). &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Verify the Digest password file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat /etc/httpd/conf.d/.digestpass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Edit the Apache configuration file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vi /etc/httpd/conf/httpd.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following inside the &lt;code&gt;&amp;lt;Directory "/var/www/html"&amp;gt;&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Directory "/var/www/html/digest"&amp;gt;
    AuthType Digest
    AuthName "Digest Auth"
    AuthUserFile /etc/httpd/conf.d/.digestpass
    Require valid-user
&amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create an index.html file in the protected directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vi /var/www/html/digest/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add what you want to display when the user is authorized:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You're successfully authorized
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;i&lt;/code&gt; to start typing, turning on the INSERT MODE. &lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;esc&lt;/code&gt;, type &lt;code&gt;:wq&lt;/code&gt;, and press &lt;code&gt;Enter&lt;/code&gt; to save the file and exit the INSERT MODE. &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Restart the Apache server:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Test the Authentication using &lt;code&gt;curl&lt;/code&gt; command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -L --digest -u username:password http://xx.xx.xx.xx/digest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see &lt;code&gt;You're successfully authorized&lt;/code&gt;, authentication is working correctly. &lt;/p&gt;

&lt;h2&gt;
  
  
  Key Differences Between Basic and Digest Authentication
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feature:&lt;/strong&gt; Digest Authentication is more secure than Basic Authentication. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password Transmission:&lt;/strong&gt; While Basic Authentication sends as Base64 (plaintext), Digest Authentication sends as a hashed value. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replay Attack Risk:&lt;/strong&gt; Digest Authentication is lower due to its nonce mechanism. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser Support:&lt;/strong&gt; While Basic Authentication is widely supported, Digest Authentication is less common. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Others:&lt;/strong&gt; - Digest Authentication is a more secure alternative to Basic Authentication because Basic only uses HTTPS. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Both Basic and Digest Authentication provide ways to restrict access to web resources. Basic Authentication is easy to implement but should always be used with HTTPS to prevent credential exposure. Digest Authentication offers better security through hashing and challenge-response mechanisms, making it a more secure choice for sensitive data. &lt;br&gt;
If you're working with an Apache web server, implementing these authentication methods is straightforward and enhances security for restricted resources.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://qiita.com/miyuki_samitani/items/ccf9217a058019ca8d59" rel="noopener noreferrer"&gt;https://qiita.com/miyuki_samitani/items/ccf9217a058019ca8d59&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/699apachedigest.html" rel="noopener noreferrer"&gt;https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/699apachedigest.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>digestauthentication</category>
      <category>apache</category>
      <category>http</category>
      <category>server</category>
    </item>
    <item>
      <title>Understanding Basic Authentication</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Wed, 19 Feb 2025 19:03:07 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/basic-vs-digest-authentication-56hn</link>
      <guid>https://dev.to/ryoichihomma/basic-vs-digest-authentication-56hn</guid>
      <description>&lt;p&gt;I recently had an opportunity to use &lt;strong&gt;Basic Authentication&lt;/strong&gt; and &lt;strong&gt;Digest Authentication&lt;/strong&gt;, so I'd like to share what I learned about these two authentication methods. This article will focus on Basic Authentication, especially how it works and how to implement it.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Authentication
&lt;/h2&gt;

&lt;p&gt;Basic Authentication is a simple authentication mechanism where the client sends credentials like username and password encoded in Base64 with each HTTP request. While Base64 encoding is not encryption, it allows the credentials to be included in a standard format. Since it lacks encryption, it is recommended to use HTTPS to secure credentials in transit. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Follow these steps to implement Basic Authentication on the Apache server: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Apache using yum:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install httpd -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a protected directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir -p /var/www/html/basic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;/basic&lt;/code&gt; can be anything.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the &lt;code&gt;.htpasswd&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo htpasswd -c /etc/httpd/.htpasswd username
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll be asked to type and confirm the password.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit the Apache configuration file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vi /etc/httpd/conf/httpd.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following inside the &lt;code&gt;&amp;lt;Directory "/var/www/html"&amp;gt;&lt;/code&gt; section (usually from 160 lines):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Directory "var/www/html/basic"&amp;gt;
    AuthType Basic
    AuthName "Basic Auth"
    AuthUserFile /etc/httpd/.htpasswd
    Require user username
&amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create an index.html file in the protected directory:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vi /var/www/html/basic/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add something you want to display when the user is authorized:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You're successfully authorized
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;i&lt;/code&gt; to start typing in the INSERT MODE. &lt;/li&gt;
&lt;li&gt;To exit the INSERT MODE, press &lt;code&gt;esc&lt;/code&gt;, type &lt;code&gt;:wq&lt;/code&gt;, and press &lt;code&gt;Enter&lt;/code&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Restart the Apache server:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart httpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Test the authentication using &lt;code&gt;curl&lt;/code&gt; command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -L -u username:password http://xx.xx.xx.xx/basic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see &lt;code&gt;You're successfully authorized&lt;/code&gt;, authentication is working correctly. &lt;/p&gt;

&lt;p&gt;In the next article, &lt;a href="https://dev.to/ryoichihomma/understanding-digest-authentication-2oc5"&gt;Understanding Digest Authentication&lt;/a&gt;, I will explore more about Digest Authentication. &lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/698apachebasic.html" rel="noopener noreferrer"&gt;https://atmarkit.itmedia.co.jp/flinux/rensai/linuxtips/698apachebasic.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>basicauthentication</category>
      <category>apache</category>
      <category>http</category>
      <category>server</category>
    </item>
    <item>
      <title>Exploring Promises in JavaScript</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Sun, 19 Jan 2025 05:57:40 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/exploring-promises-in-javascript-2k8n</link>
      <guid>https://dev.to/ryoichihomma/exploring-promises-in-javascript-2k8n</guid>
      <description>&lt;p&gt;If you've ever worked with asynchronous programming in JavaScript, you've likely come across Promises. At first glance, Promises may seem confusing, but once you understand, they become an indispensable tool in your developer toolkit. This article explains what Promises are, how they work, and why they matter. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Promise?
&lt;/h2&gt;

&lt;p&gt;A Promise is an object in JavaScript that represents the eventual completion or failure of an asynchronous operation. In simpler terms, it's a way to handle operations that don't immediately return a result, like fetching data from an API or reading a file. &lt;/p&gt;

&lt;p&gt;Promises have three possible states: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pending&lt;/strong&gt;: The operation is still in progress. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fulfilled&lt;/strong&gt;: The operation completed successfully. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rejected&lt;/strong&gt;: The operation failed. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once a Promise is fulfilled or rejected, its state becomes immutable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do We Need Promises?
&lt;/h2&gt;

&lt;p&gt;JavaScript is single-threaded, meaning that it can only perform one operation at a time. Asynchronous operations are used to avoid blocking the main thread. Before Promises, callbacks were the primary way to handle such operations. However, nested callbacks made the code difficult to read and maintain. Promises solve this problem by providing a cleaner, more readable syntax for managing asynchronous tasks. &lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of a Promise
&lt;/h2&gt;

&lt;p&gt;Creating a Promise involves using the &lt;code&gt;Promise&lt;/code&gt; constructor, which takes a function executor with two arguments: &lt;code&gt;resolve&lt;/code&gt; and &lt;code&gt;reject&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;myPromise&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;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;success&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Operation was successful!&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Operation failed.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;resolve&lt;/code&gt;&lt;/strong&gt;: Call this function when the operation completes successfully. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;reject&lt;/code&gt;&lt;/strong&gt;: Call this function when the operation fails. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Consuming a Promise
&lt;/h2&gt;

&lt;p&gt;You can use &lt;code&gt;.then()&lt;/code&gt;, &lt;code&gt;.catch()&lt;/code&gt;, and &lt;code&gt;.finally()&lt;/code&gt; to handle the outcomes of a Promise:&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="nx"&gt;myPromise&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;result&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="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Operation was successful!"&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Operation failed." &lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;finally&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Operation complete.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.then()&lt;/code&gt;&lt;/strong&gt;: Executes when the Promise is fulfilled. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.catch()&lt;/code&gt;&lt;/strong&gt;: Executes when the Promise is rejected. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.finally()&lt;/code&gt;&lt;/strong&gt;: Executes regardless of the outcome (fulfilled or rejected). &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Real-World Example: Fetching Data
&lt;/h2&gt;

&lt;p&gt;Promises are widely used with APIs. Here's an example using the &lt;code&gt;fetch&lt;/code&gt; API:&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="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://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Network response was not ok&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="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;There was a problem with the fetch operation: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fetch&lt;/code&gt; returns a Promise. &lt;/li&gt;
&lt;li&gt;The first &lt;code&gt;.then()&lt;/code&gt; parses the response. &lt;/li&gt;
&lt;li&gt;The second &lt;code&gt;.then()&lt;/code&gt; processes the parsed data. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.catch()&lt;/code&gt; handles any errors that occur. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advanced: Chaining Promises
&lt;/h2&gt;

&lt;p&gt;One of the strengths of Promises is chaining. Each &lt;code&gt;.then()&lt;/code&gt; returns a new Promise, allowing you to chain multiple asynchronous operations:&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="nf"&gt;getUser&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;user&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getUserPosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&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="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;displayPosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps the code clean and avoids deeply nested callbacks. &lt;/p&gt;

&lt;h2&gt;
  
  
  Async/Await: A Syntactic Sugar
&lt;/h2&gt;

&lt;p&gt;Introduced in ES2017, &lt;code&gt;async/await&lt;/code&gt; simplifies working with Promises by allowing you to write asynchronous code that looks asynchronous:&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="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https:///api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Error fetching data: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Under the hood, &lt;code&gt;async/await&lt;/code&gt; is built on Promises, so understanding Promises is crucial to using &lt;code&gt;async/await&lt;/code&gt; effectively. &lt;/p&gt;

&lt;h2&gt;
  
  
  Key Benefits of Promises
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Readability&lt;/strong&gt;: Promises make asynchronous code easier to read and maintain. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;: Centralized error handling with &lt;code&gt;.catch()&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chaining&lt;/strong&gt;: Enables sequential execution9 of asynchronous operations. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Common Pitfalls
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting to return a Promise&lt;/strong&gt;: Always return a Promise when chaining. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unhandled Rejections&lt;/strong&gt;: Use &lt;code&gt;.catch()&lt;/code&gt; or &lt;code&gt;try-catch&lt;/code&gt; to handle errors. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mixing Callbacks and Promises&lt;/strong&gt;: Stick to one approach to avoid confusion. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Promises are a powerful feature of JavaScript that simplifies handling asynchronous operations. By understanding their structure and usage, you can write cleaner, more maintainable code. Bookmark this post as a reference for the next time you need a quick refresher on Promises! &lt;/p&gt;

&lt;p&gt;If you have any questions or examples you'd like to share, drop them in the comments below. Your comments and feedback are always appreciated!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>promise</category>
      <category>oop</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why React Hook Form and Zod are Essential to Build Contact Form</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Mon, 30 Dec 2024 15:28:45 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/why-react-hook-form-and-zod-are-essential-to-build-contact-form-5bkp</link>
      <guid>https://dev.to/ryoichihomma/why-react-hook-form-and-zod-are-essential-to-build-contact-form-5bkp</guid>
      <description>&lt;p&gt;Creating a robust and user-friendly contact form is a vital part of any web application. A poorly implemented form can lead to user frustration, data inconsistencies, or even security vulnerabilities. Leveraging &lt;a href="https://react-hook-form.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;React Hook Form&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://zod.dev/" rel="noopener noreferrer"&gt;&lt;strong&gt;Zod&lt;/strong&gt;&lt;/a&gt; simplifies this process while ensuring a seamless experience for both developers and users. &lt;br&gt;
In this article, we'll explore why these two tools are essential for building contact forms and how they address common challenges in form development. &lt;/p&gt;
&lt;h3&gt;
  
  
  Agenda
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The Challenges of Form Handling&lt;/li&gt;
&lt;li&gt;Why Use React Hook Form?&lt;/li&gt;
&lt;li&gt;Why Use Zod?&lt;/li&gt;
&lt;li&gt;Why Combine React Hook Form and Zod?&lt;/li&gt;
&lt;li&gt;Real-World Example&lt;/li&gt;
&lt;li&gt;Reference&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Challenges of Form Handling
&lt;/h2&gt;

&lt;p&gt;Form handling in React projects can quickly become cumbersome. Traditional approaches often involve managing state manually, writing complex validation logic, and handling edge cases, such as asynchronous validation. Common pitfalls include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Performance Bottlenecks&lt;/strong&gt;: Frequent re-renders as form states change. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Complex Validation Logic&lt;/strong&gt;: Writing and maintaining custom validation rules can lead to messy code. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Management&lt;/strong&gt;: Displaying appropriate error messages for each input field is tricky without a structured approach. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;React Hook Form and Zod address these challenges head-on, making form development more efficient and reliable. &lt;/p&gt;
&lt;h2&gt;
  
  
  Why Use React Hook Form?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://react-hook-form.com/" rel="noopener noreferrer"&gt;React Hook Form&lt;/a&gt; is a lightweight library that simplifies form handling in React applications. Here are some reasons why it's an excellent choice: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Minimal Re-Renders&lt;/strong&gt;: React Hook Form reduces performance overhead by leveraging uncontrolled components and only updating the DOM when necessary. This leads to faster forms, even with complex validations. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intuitive API&lt;/strong&gt;: The API is simple and developer-friendly. Integrating features like validation, error handling, and field management is straightforward. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Built-in Features&lt;/strong&gt;: 

&lt;ul&gt;
&lt;li&gt;Real-time validation&lt;/li&gt;
&lt;li&gt;Conditional rendering of error messages&lt;/li&gt;
&lt;li&gt;Integration with external schema validation libraries like Zod. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible Controller Component&lt;/strong&gt;: React Hook Form provides a Controller component to bridge the gap between controlled components like custom UI libraries and its native functionality. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Why Use Zod?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://zod.dev/" rel="noopener noreferrer"&gt;Zod&lt;/a&gt; is a TypeScript-first schema validation library with static type inference that enables you to define and enforce validation rules with confidence. Here's why it's a game-changer: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Type Safety&lt;/strong&gt;: Zod generates TypeScript types directly from your schema, ensuring compile-time safety. This eliminates the risk of runtime type errors.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Declarative Validation&lt;/strong&gt;: Instead of writing imperative validation logic, you declare rules in a concise and readable manner. For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { z } from 'zod'; 

export const contactFormSchema = z.object({
  name: z.string().min(1, 'Name is required'),
  email: z.string().min(1, 'Email is required').email();
  message: z.string().min(20, 'Message must be at least 20 characters long'),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Integration with React Hook Form&lt;/strong&gt;: Zod integrates seamlessly with React Hook Form via the &lt;code&gt;zodResolver&lt;/code&gt;. This means you can define your schema and let React Hook Form handle the validation process. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Feedback&lt;/strong&gt;: Zod provides detailed and descriptive error messages, making it easier for users to understand what went wrong. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The Power of Combining React Hook Form and Zod
&lt;/h2&gt;

&lt;p&gt;Using React Hook Form and Zod together unlocks a new level of efficiency and reliability in form handling. Here's how they work in tandem: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Effortless Validation Integration&lt;/strong&gt;: With the &lt;code&gt;zodResolver&lt;/code&gt;, you can connect your Zod schema to React Hook Form in just a few lines:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useForm } from 'react-hook-form'; 
import { zodResolver } from '@hookform/resolver/zod'; 

const { register, handleSubmit, formState: { errors } } = useForm({
  resolver: zodResolver(contactFormSchema),
}); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Error Handling&lt;/strong&gt;: The errors object provided by React Hook Form is automatically populated with Zod's validation feedback, which you can display in your UI:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input {...register('email')} /&amp;gt;
{errors.email &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.email.message}&amp;lt;/p&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplified Codebase&lt;/strong&gt;: By offloading validation logic to Zod and leveraging the React Hook Form declarative approach, your code remains clean and maintainable. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: As your form grows, adding new fields and rules is  straightforward with Zod schemas and React Hook Form's flexible API. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Real-World Example
&lt;/h2&gt;

&lt;p&gt;Let's consider a contact form with fields for name, email, and message. Here's how it might look like with React Hook Form and Zod:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useForm } from 'react-hook-form';
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';

export const contactFormSchema = z.object({
  name: z.string().min(1, 'Name is required'),
  email: z.string().min(1, 'Email is required').email('Invalid email address'),
  message: z.string().min(20, 'Message must be at least 20 characters long'),
});

type ContactFormInputs = z.infer&amp;lt;typeof contactFormSchema&amp;gt;;

export default function ContactForm() {
  const { register, handleSubmit, formState: { errors } } = useForm&amp;lt;ContactFormInputs&amp;gt;({
    resolver: zodResolver(contactFormSchema),
  });

  const onSubmit = (data: ContactFormInputs) =&amp;gt; {
    console.log(data);
  };

  return (
    &amp;lt;form onSubmit={handleSubmit(onSubmit)}&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Name:&amp;lt;/label&amp;gt;
        &amp;lt;input {...register('name')} /&amp;gt;
        {errors.name &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.name.message}&amp;lt;/p&amp;gt;}
      &amp;lt;/div&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Email:&amp;lt;/label&amp;gt;
        &amp;lt;input {...register('email')} /&amp;gt;
        {errors.email &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.email.message}&amp;lt;/p&amp;gt;}
      &amp;lt;/div&amp;gt;

      &amp;lt;div&amp;gt;
        &amp;lt;label&amp;gt;Message:&amp;lt;/label&amp;gt;
        &amp;lt;textarea {...register('message')} /&amp;gt;
        {errors.message &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{errors.message.message}&amp;lt;/p&amp;gt;}
      &amp;lt;/div&amp;gt;

      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;Refer to this &lt;a href="https://youtu.be/u6PQ5xZAv7Q?si=C4zFcKFYVx2Vl5Tl" rel="noopener noreferrer"&gt;YouTube video&lt;/a&gt; to learn more about React Hook Form and Zod.&lt;/p&gt;

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

&lt;p&gt;Building a contact form that is both performant and user-friendly is no small feat. By combining &lt;strong&gt;React Hook Form&lt;/strong&gt; and &lt;strong&gt;Zod&lt;/strong&gt;, you gain access to a powerful toolkit that streamlines form development, enforces strong validation rules, and enhances the user experience. These tools not only save development time but also improve code maintainability, scalability, and performance. If you haven't already, give React Hook Forma and Zod a try in your next project. &lt;/p&gt;

&lt;p&gt;Please feel free to leave comments. Your feedback is always appreciated. &lt;/p&gt;

</description>
      <category>reacthookform</category>
      <category>zod</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How to Implement an Auto-Reply System Using EmailJS in Your React Project</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Sun, 29 Dec 2024 07:50:09 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/how-to-implement-an-auto-reply-system-using-emailjs-in-your-react-project-4p70</link>
      <guid>https://dev.to/ryoichihomma/how-to-implement-an-auto-reply-system-using-emailjs-in-your-react-project-4p70</guid>
      <description>&lt;p&gt;Setting up an auto-reply system for your React project can significantly enhance the user experience by providing instant feedback when users submit forms. EmailJS is an excellent service for this use case as it enables you to send emails directly from your client-side app without requiring a dedicated backend. In this article, we'll explore two ways to integrate EmailJS into your React project: using the SDK and the REST API. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;A React project setup (using Create React App, Vite, or your preferred framework).&lt;/li&gt;
&lt;li&gt;An EmailJS account. Sign up &lt;a href="https://www.emailjs.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A service ID, template ID, and public key from your EmailJS dashboard. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation Using the EmailJS SDK
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1) Install the EmailJS SDK
&lt;/h3&gt;

&lt;p&gt;Install the EmailJS SDK using npm or yarn:&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 --save @emailjs/browser 
yarn add @emailjs/browser  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2) Configure the SDK
&lt;/h3&gt;

&lt;p&gt;Import and configure the SDK in your React component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import emailjs from '@emailjs/browse'; 

const AutoReplyForm = () =&amp;gt; {
  const formRef = React.useRef();

  const sendEmail = (e) =&amp;gt; {
    e.preventDefault();

    emailjs
      .sendForm(
        'YOUR_SERVICE_ID',
        'YOUR_TEMPLATE_ID',
        formRef.current,
        'YOUR_PUBLIC_KEY'
      )
      .then(
        (result) =&amp;gt; {
          console.log('Success:', result.text);
          alert('Email sent successfully!');
        },
        (error) =&amp;gt; {
          console.error('Error:', error.text);
          alert('Failed to send email.');
        }
      );
  };

  return (
    &amp;lt;form ref={formRef} onSubmit={sendEmail}&amp;gt;
      &amp;lt;input type="text" name="user_name" placeholder="Your Name" required /&amp;gt;
      &amp;lt;input type="email" name="user_email" placeholder="Your Email" required /&amp;gt;
      &amp;lt;textarea name="message" placeholder="Your Message" required /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Send&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
};

export default AutoReplyForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Key Points:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;YOUR_SERVICE_ID&lt;/code&gt;, &lt;code&gt;YOUR_SERVICE_ID&lt;/code&gt;, &lt;code&gt;YOUR_TEMPLATE_ID&lt;/code&gt;, and &lt;code&gt;YOUR_PUBLIC_KEY&lt;/code&gt; with the credentials from your EmailJS dashboard.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;sendForm&lt;/code&gt; method automatically parses the form data. &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Reference:
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://www.emailjs.com/docs/sdk/installation/" rel="noopener noreferrer"&gt;EmailJS SDK Installation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative Method: Implementation Using the EmailJS REST API
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1) Install Axios
&lt;/h3&gt;

&lt;p&gt;Install Axios for making HTTP requests:&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 axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2) Create the REST API Integration
&lt;/h3&gt;

&lt;p&gt;Use Axios to send a POST request to the EmailJS REST endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';
import axios from 'axios';

const AutoReplyForm = () =&amp;gt; {
  const [formData, setFormData] = useState({
    user_name: '',
    user_email: '',
    message: '',
  });

  const handleChange = (e) =&amp;gt; {
    setFormData({ ...formData, [e.target.name]: e.target.value });
  };

  const sendEmail = async (e) =&amp;gt; {
    e.preventDefault();

    const payload = {
      service_id: 'YOUR_SERVICE_ID',
      template_id: 'YOUR_TEMPLATE_ID',
      user_id: 'YOUR_PUBLIC_KEY',
      template_params: formData,
    };

    try {
      const response = await axios.post('https://api.emailjs.com/api/v1.0/email/send', payload);
      console.log('Success:', response.data);
      alert('Email sent successfully!');
    } catch (error) {
      console.error('Error:', error);
      alert('Failed to send email.');
    }
  };

  return (
    &amp;lt;form onSubmit={sendEmail}&amp;gt;
      &amp;lt;input
        type="text"
        name="user_name"
        placeholder="Your Name"
        value={formData.user_name}
        onChange={handleChange}
        required
      /&amp;gt;
      &amp;lt;input
        type="email"
        name="user_email"
        placeholder="Your Email"
        value={formData.user_email}
        onChange={handleChange}
        required
      /&amp;gt;
      &amp;lt;textarea
        name="message"
        placeholder="Your Message"
        value={formData.message}
        onChange={handleChange}
        required
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Send&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
};

export default AutoReplyForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Key Points:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The REST API requires a payload containing &lt;code&gt;service_id&lt;/code&gt;, &lt;code&gt;template_id&lt;/code&gt;, &lt;code&gt;user_id&lt;/code&gt;, and &lt;code&gt;template_params&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;YOUR_SERVICE_ID&lt;/code&gt;, &lt;code&gt;YOUR_TEMPLATE_ID&lt;/code&gt;, and &lt;code&gt;YOUR_PUBLIC_KEY&lt;/code&gt; accordingly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Reference:
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://www.emailjs.com/docs/rest-api/send/" rel="noopener noreferrer"&gt;EmailJS REST API&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to Find the IDs and Keys on EmailJS Dashboard
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SERVICE_ID&lt;/code&gt;: &lt;br&gt;
Go to the &lt;a href="https://dashboard.emailjs.com/admin" rel="noopener noreferrer"&gt;dashboard&lt;/a&gt; → &lt;code&gt;Email Services&lt;/code&gt; tab in the sidebar menu. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;TEMPLATE_ID&lt;/code&gt;: &lt;br&gt;
Go to the &lt;code&gt;Email Templates&lt;/code&gt; tab in the sidebar menu and click &lt;code&gt;Create New Template&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;PUBLIC_KEY&lt;/code&gt;: &lt;br&gt;
Go to &lt;a href="https://dashboard.emailjs.com/admin/account" rel="noopener noreferrer"&gt;Account&lt;/a&gt; in the top menu bar and choose &lt;code&gt;Generate&lt;/code&gt; tab. You'll find your &lt;code&gt;Public key&lt;/code&gt; and &lt;code&gt;Private key&lt;/code&gt; in the API keys section. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to Customize Template
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Customize Content:
&lt;/h3&gt;

&lt;p&gt;You will receive this template as a notification when someone sends you the form.&lt;br&gt;
&lt;a href="https://media2.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%2Fmm34jg433d0md5nk3mf9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fmm34jg433d0md5nk3mf9.png" alt="content" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Customize Auto-Reply Message:
&lt;/h3&gt;

&lt;p&gt;This template is what someone will receive once they submit the form. &lt;br&gt;
&lt;a href="https://media2.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%2F10p2e944j63ovyfcz6vt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F10p2e944j63ovyfcz6vt.png" alt="auto-reply" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;code&gt;{{ subject }}&lt;/code&gt;, &lt;code&gt;{{ sender_name }}&lt;/code&gt;, &lt;code&gt;{{ message }}&lt;/code&gt;, &lt;code&gt;{{ email }}&lt;/code&gt;, etc. need to match your variable names in your code. &lt;/p&gt;

&lt;h2&gt;
  
  
  Securing the IDs API Keys
&lt;/h2&gt;

&lt;p&gt;Do not forget to secure your EmailJS IDs and API keys so that they wouldn't be exposed to the client side. To do that, refer to my another article that provides a step-by-step tutorial, &lt;a href="https://dev.to/ryoichihomma/how-to-protect-only-api-keys-instead-of-entire-files-on-github-and-from-its-commit-history-3120"&gt;"How to Hide Only API Keys Instead of Entire Files on GitHub and From Its Commit History"&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Both methods provide effective ways to implement an auto-reply system with EmailJS in your React project. The SDK is great for quick setups, while the REST API offers more flexibility for custom implementations. Choose the approach that best suits your project's requirements. &lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to leave comments. Your feedback is always appreciated. &lt;/p&gt;

</description>
      <category>eamiljs</category>
      <category>autoreply</category>
      <category>react</category>
      <category>restapi</category>
    </item>
    <item>
      <title>How to Implement Real-Time Email Validation Using ZeroBounce API</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Fri, 27 Dec 2024 11:41:48 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/how-to-implement-real-time-email-validation-4c0e</link>
      <guid>https://dev.to/ryoichihomma/how-to-implement-real-time-email-validation-4c0e</guid>
      <description>&lt;p&gt;Validating email addresses in real time can significantly enhance the user experience and ensure the accuracy of data in your system. In this article, you'll learn how to integrate the ZeroBounce API into your web application to validate email addresses as users type them into a form. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is ZeroBounce?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.zerobounce.net/?campaignid=1070376639&amp;amp;groupid=51898694789&amp;amp;adid=357518452232&amp;amp;gad_source=1&amp;amp;gclid=Cj0KCQiAvbm7BhC5ARIsAFjwNHs6HxKp3fhV6kr-J9nz7CcnVAEiHWjHCla6CsAYBFFUaf58fPVbhkcaAhZeEALw_wcB" rel="noopener noreferrer"&gt;ZeroBounce&lt;/a&gt; is a powerful email validation and deliverability platform that helps developers and businesses verify email addresses. By integrating their API, you can: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce bounce rates.&lt;/li&gt;
&lt;li&gt;Improve email list quality.&lt;/li&gt;
&lt;li&gt;Prevent spam signups. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's dive into how to set up real-time email validation with ZeroBounce in a React application. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before you begin, ensure you have the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A basic understanding of React. &lt;/li&gt;
&lt;li&gt;Node.js installed on your local machine. &lt;/li&gt;
&lt;li&gt;A ZeroBounce account and API key. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up the Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Create a React App
&lt;/h3&gt;

&lt;p&gt;First, create a new React app using Vite or Create React App command. I'll follow Vite here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@leatest real-time-email-validation --template
cd real-time-email-validation
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Install Axios
&lt;/h3&gt;

&lt;p&gt;Install Axios for making HTTP requests:&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 axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Building the Contact Form
&lt;/h2&gt;

&lt;p&gt;Create a simple contact form to capture user input and validate the email address. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Build the Form Component
&lt;/h3&gt;

&lt;p&gt;Create a &lt;code&gt;ContctForm&lt;/code&gt; component to handle user input and fetch the API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState} from 'react'; 
import axios from 'axios'; 

const ContactForm = () =&amp;gt; {
  const [email, setEmail] = useState("");
  const [validationMessage, setValidationMessage] = useState(null);
  const [error, setError] = useState(null);

  const validateEmail = async () =&amp;gt; {
    try {
       const response = await axios.get(
         `https://api.zerobounce.net/v2/validate?api_key=YOUR_API_KEY&amp;amp;email=${email}`

       if (response.data.status === 'valid') {
         setValidationMessage('Email is valid.');
       } else {
         setValidationMessage('Invalid email address.');
       } 
    } catch (err) {
      console.log('Error validating email:', err);
      setError('Unable to validate email at the moment.');
    }
  };

  const handleSubmit = (e) =&amp;gt; {
    e.preventDefault();
    setValdationMessage(null);
    setError(null);
    validateEmail();
  };

  return (
    &amp;lt;form onSubmit={handleSubmit} &amp;gt;
      &amp;lt;&amp;gt;
        &amp;lt;label htmlFor='email'&amp;gt;Email:&amp;lt;/label&amp;gt;
        &amp;lt;input 
          id='email'
          type='email'
          value={email}
          onChange={(e) =&amp;gt; setEmail(e.target.value)}
          required
         /&amp;gt;
      &amp;lt;/&amp;gt;
      &amp;lt;button type='submit'&amp;gt;Validate Email&amp;lt;/button&amp;gt;
      {validationMessage &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{validationMessage}&amp;lt;/p&amp;gt;}
      {error &amp;amp;&amp;amp; &amp;lt;p style={{ color: 'red' }}&amp;gt;{error}&amp;lt;/p&amp;gt;}
    &amp;lt;/form&amp;gt;
  );
};

export default ContactForm;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Securing the API Key
&lt;/h2&gt;

&lt;p&gt;Do not forget to secure your ZeroBounce API key so that it wouldn't be  exposed to the client side. To do that, refer to my another article that provides a step-by-step tutorial, "&lt;a href="https://dev.to/ryoichihomma/how-to-protect-only-api-keys-instead-of-entire-files-on-github-and-from-its-commit-history-3120"&gt;How to Hide Only API Keys Instead of Entire Files on GitHub and From Its Commit History&lt;/a&gt;".&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the Application
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Replace &lt;code&gt;YOUR_API_KEY&lt;/code&gt; in the &lt;code&gt;axios.get&lt;/code&gt; call with your ZeroBounce API key. &lt;/li&gt;
&lt;li&gt;Start the development server:
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open your browser and navigate to the local server (e.g., &lt;code&gt;http://localhost:5173&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Enter an email address into the form and click "Validate Email". The application will display whether the email is valid or not. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;By integrating the ZeroBounce API into your React app, you can ensure the validity of email addresses in real time. This not only improves the user experience but also helps maintain a clean and effective email list. Try implementing this solution in your next project and take your email validation to the next level!&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, feel free to leave a comment or share your thoughts! Your feedback is always appreciated!&lt;/p&gt;

</description>
      <category>realtimeemailvalidation</category>
      <category>zerobounce</category>
      <category>api</category>
      <category>react</category>
    </item>
    <item>
      <title>How to Hide Only API Keys Instead of Entire Files on GitHub and From Its Commit History</title>
      <dc:creator>Ryoichi Homma</dc:creator>
      <pubDate>Mon, 16 Dec 2024 23:36:14 +0000</pubDate>
      <link>https://dev.to/ryoichihomma/how-to-protect-only-api-keys-instead-of-entire-files-on-github-and-from-its-commit-history-3120</link>
      <guid>https://dev.to/ryoichihomma/how-to-protect-only-api-keys-instead-of-entire-files-on-github-and-from-its-commit-history-3120</guid>
      <description>&lt;p&gt;When you work on software projects, it's essential to deal with sensitive data like API keys. Making these keys invisible is crucial to avoid security breaches. You might initially consider excluding the entire files that contain API keys by adding them to your &lt;code&gt;.gitignore&lt;/code&gt; file. However, this approach has its downsides, especially if those files contain non-sensitive code that you want to remain in your repository. This article will guide you on how to hide API keys properly without excluding the entire file and removing them from the commit history if sensitive data has been already pushed. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hide API Keys?
&lt;/h2&gt;

&lt;p&gt;API keys grant access to services and data. Exposing them publicly can lead to the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unauthorized access to your account. &lt;/li&gt;
&lt;li&gt;Potential misuse of your quotas or sensitive services. &lt;/li&gt;
&lt;li&gt;Financial losses if the APIs involve paid services. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide to Hide API Keys
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1) Move API Keys to an Environment File
&lt;/h3&gt;

&lt;p&gt;Instead of hardcoding API keys in your secure files, create &lt;code&gt;.env&lt;/code&gt; file and store the keys in it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .env file
API_KEY=your_api_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2) Add &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;To ensure the &lt;code&gt;.env&lt;/code&gt; file which contains your API keys is not pushed to GitHub, add it to your &lt;code&gt;.gitignore&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Environment variables
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will prevent Git from tracking the &lt;code&gt;.env&lt;/code&gt; file. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3) Installation and Configuration
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Install dependencies
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install dotenv --save -dev @type/node 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Configure &lt;code&gt;vite.config.ts&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import dotenv from "dotenv";

dotenv.config(); // Load .env file

export default defineConfig({
  plugins: [react()],

  // Add this
  define: {
    "process.env": process.env,
  },
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4) Update Your Code to Import Environment Variables
&lt;/h3&gt;

&lt;p&gt;Your existing code may be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios

const your_api_variable = "your_api_key";

export const function = async () =&amp;gt; {
  try {
    const response = await axios.get(`https://api.random_api.net/example_api_key=${your_api_variable}`);
    return response.data.status === "valid";
  } catch (error) {
    console.error("Invalid", error);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Updated version:&lt;/strong&gt; Refactor your code to fetch the API key from environment variables of &lt;code&gt;.env&lt;/code&gt; file using &lt;code&gt;process.env.&lt;/code&gt; prefix like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from "axios

// Get API key from environment variables of .env file
const your_api_variable = process.env.API_KEY;

export const function = async () =&amp;gt; {
  try {
    const response = await axios.get(`https://api.random_api.net/example_api_key=${your_api_variable}`);
    return response.data.status === "valid";
  } catch (error) {
    console.error("Invalid", error);
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replacing your API key with &lt;code&gt;process.env.API_KEY&lt;/code&gt; lets your code import the API key as an environment variable from the &lt;code&gt;.env&lt;/code&gt; file. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5) Push Your Changes to GitHub
&lt;/h3&gt;

&lt;p&gt;Since your sensitive data is no longer hardcoded in the source files, you can safely push your files to GitHub without exposing your API keys. Ensure the &lt;code&gt;.env&lt;/code&gt; file remains untracked. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6) Remove Sensitive Data from Commit History
&lt;/h3&gt;

&lt;p&gt;If your API keys were already committed to GitHub, you must remove them from the commit history. Here's how to do it using &lt;code&gt;git filter-repo&lt;/code&gt; command: &lt;/p&gt;

&lt;h4&gt;
  
  
  Install &lt;code&gt;git filter-repo&lt;/code&gt;
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install git-filter-repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Remove Sensitive Files From Commit History
&lt;/h4&gt;

&lt;p&gt;Run the following command to rewrite your repository's history and remove sensitive files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git filter-repo --path src/api/your_file_with_sensitive_data.ts --invert-paths
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try adding &lt;code&gt;--force&lt;/code&gt; at the end if this way doesn't work. This command will remove the specified files from the commit history. &lt;/p&gt;

&lt;h4&gt;
  
  
  Force Push to Update Remote Repository
&lt;/h4&gt;

&lt;p&gt;After rewriting history, you need to force-push your changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin main --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Warning:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;This operation rewrites your repo's history. Ensure you communicate this with your team and back up your repository beforehand.&lt;/li&gt;
&lt;li&gt;If you accidentally expose your API keys, revoke them immediately and generate new ones. &lt;/li&gt;
&lt;li&gt;Use tools like &lt;a href="https://github.com/dependabot" rel="noopener noreferrer"&gt;GitHub Dependabot&lt;/a&gt; or &lt;a href="https://github.com/awslabs/git-secrets" rel="noopener noreferrer"&gt;git-secrets&lt;/a&gt; to monitor your repositories for sensitive information. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;By removing API keys to environment variables, ignoring the &lt;code&gt;.env&lt;/code&gt; file, and cleaning up commit history, you can ensure that your sensitive data remains secure while maintaining the ability to push your source code to GitHub. This approach strikes the right balance between security and collaboration. &lt;/p&gt;

&lt;p&gt;If you found this guide helpful, feel free to share this article or leave a comment below with your thoughts or additional tips!&lt;/p&gt;

</description>
      <category>dotenv</category>
      <category>gitignore</category>
      <category>api</category>
      <category>security</category>
    </item>
  </channel>
</rss>
