<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Bhavesh Rawat - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Bhavesh Rawat - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 22 May 2026 22:36:06 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/bhaveshrawat/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Make an Interactive and Dynamic Table of Contents in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ While reading some technical articles on various platforms, I kept noticing the Table of Contents section in the sidebar. Some were interactive and some were just links to those sections. A Table of Contents usually ends up being pretty helpful to re... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-make-a-dynamic-table-of-contents-in-javascript/</link>
                <guid isPermaLink="false">66d45dd6052ad259f07e4a7b</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bhavesh Rawat ]]>
                </dc:creator>
                <pubDate>Tue, 14 Nov 2023 15:22:52 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/11/Frame-32-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>While reading some technical articles on various platforms, I kept noticing the Table of Contents section in the sidebar. Some were interactive and some were just links to those sections.</p>
<p>A Table of Contents usually ends up being pretty helpful to readers. It lets you easily skim through what an article will cover and find the section you're interested in. It also lets you know if the article contains the information you’re looking for, and it's a big win for accessibility.</p>
<p>Taking inspiration from all these various platforms, I tried to build my own Table of Contents functionality. I wanted it to dynamically list all the H2 headings along with their bookmark links. I also wanted the headings to get highlighted as they get scrolled in the view. I’m excited, let’s start.</p>
<p>Note: I couldn’t use Codepen, as it uses iframes to preview results – and as of now, <a target="_blank" href="https://github.com/w3c/IntersectionObserver/issues/372">Intersection Observer acts quite finicky in iFrame</a>. Here's the <a target="_blank" href="https://gist.github.com/bhaveshxrawat/7c3b869c74797adfbb10655af2b4cfe2">gist</a> for this code.</p>
<div class="gist-block embed-wrapper" data-gist-show-loading="false" data-id="7c3b869c74797adfbb10655af2b4cfe2">
        <script src="https://gist.github.com/bhaveshxrawat/7c3b869c74797adfbb10655af2b4cfe2.js"></script></div><p> </p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To get the most out of this tutorial, you should be familiar with:</p>
<ol>
<li><p>HTML5/CSS3/JavaScript</p>
</li>
<li><p>Intersection Observer API</p>
</li>
</ol>
<p>Alright, now let's dive in.</p>
<h2 id="heading-setting-up-the-project">Setting Up the Project</h2>
<p>First things first, let’s set up the HTML structure for our Table of Contents. It'll be nothing fancy – just an <code>&lt;article&gt;</code> tag wrapping all the content stuff, with an <code>&lt;aside&gt;</code> tag as a sibling, all being wrapped up by the <code>&lt;main&gt;</code> tag.</p>
<p>Here's what that'll look like:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Main Heading<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Heading First<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Lorem ipsum dolor sit...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Heading Second<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Lorem ipsum dolor sit...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Heading Third<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Lorem ipsum dolor sit...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">aside</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">aside</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>The <code>&lt;aside&gt;</code> tag is empty as it will get populated depending upon the content in the <code>&lt;article&gt;</code> using JavaScript.</p>
<p>We're done with the structure part. Let's do some styling, which will help us distinguish between the inactive and active links.</p>
<h2 id="heading-how-to-add-the-styling">How to Add the Styling</h2>
<p>I have imported a Google font called DM Sans for this mini-project. In my CSS, I'm using native nesting.</p>
<pre><code class="lang-css"><span class="hljs-keyword">@import</span> url(<span class="hljs-string">'https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;600&amp;display=swap'</span>);

<span class="hljs-selector-tag">html</span> {
    <span class="hljs-attribute">scroll-padding</span>: <span class="hljs-number">3.125rem</span>; 
    <span class="hljs-attribute">font-family</span>: <span class="hljs-string">'DM Sans'</span>, sans-serif;
  }
  <span class="hljs-selector-tag">main</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">2rem</span>;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">3</span>fr <span class="hljs-number">1</span>fr;
  }
  <span class="hljs-selector-tag">aside</span> {
    <span class="hljs-attribute">align-self</span>: start;
    <span class="hljs-attribute">position</span>: sticky;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0.625rem</span>;
    ul {
      li {
        a {
          <span class="hljs-attribute">transform-origin</span>: left;
          <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.1s</span> linear;
          &amp;.active {
            <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">600</span>;
            <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1.1</span>);
          }
        }
      }
    }
  }
  <span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">767px</span>) {
    <span class="hljs-selector-tag">main</span> {
      <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr;
  }
    <span class="hljs-selector-tag">aside</span> {
      <span class="hljs-attribute">display</span>: none;
    }
  }
</code></pre>
<p>I used <code>display: grid;</code> to put a layout together where the content takes up three quarters of the container (in this case, the viewport) space, and Table of Contents takes up the remaining fourth of the space.</p>
<p>I'm keeping the <code>&lt;aside&gt;</code> sticky so that it stays in the view while the content is being scrolled. We need to experience the interactivity and behavior of the 'Table of Contents, don't we?</p>
<h2 id="heading-how-to-build-the-logic">How to Build the Logic</h2>
<p>Now, here comes the fun part – and definitely the most important part. Let's start with what we can achieve easily and build upon that.</p>
<h3 id="heading-build-the-dynamic-table-of-contents-feature">Build the dynamic table of contents feature</h3>
<p>First, we need to store all the <code>H2</code> elements in a variable, and that's what we'll do in the first line. Next, we will select the <code>aside</code> elements, as we have to populate it with something. Then, we'll create a new <code>ul</code> element and store it in the variable <code>ul</code>. After doing that, we append the newly created <code>ul</code> element as a child of the <code>aside</code> element.</p>
<p>Here's what that looks like:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> headings = <span class="hljs-built_in">Array</span>.from(<span class="hljs-built_in">document</span>.getElementsByTagName(<span class="hljs-string">"h2"</span>));
<span class="hljs-keyword">const</span> aside = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">"aside"</span>);
<span class="hljs-keyword">const</span> ul = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"ul"</span>);
aside.appendChild(ul);
headings.map(<span class="hljs-function">(<span class="hljs-params">heading</span>) =&gt;</span> {
    <span class="hljs-keyword">const</span> id = heading.innerText.toLowerCase().replaceAll(<span class="hljs-string">" "</span>, <span class="hljs-string">"_"</span>);
    heading.setAttribute(<span class="hljs-string">"id"</span>, id);
    <span class="hljs-keyword">const</span> anchorElement = <span class="hljs-string">`&lt;a href="#<span class="hljs-subst">${id}</span>"&gt;<span class="hljs-subst">${heading.textContent}</span>&lt;/a&gt;`</span>;
    <span class="hljs-keyword">const</span> keyPointer = <span class="hljs-string">`&lt;li&gt;<span class="hljs-subst">${anchorElement}</span>&lt;/li&gt;`</span>;
    ul.insertAdjacentHTML(<span class="hljs-string">"beforeend"</span>, keyPointer);
});
</code></pre>
<p>Now, we use the <code>map</code> function to iterate over and perform a function for every <code>H2</code> element. First, we create an <code>id</code> for each <code>h2</code> element by converting the text content to lowercase and replacing spaces with underscores. This <code>id</code> is used for linking to the corresponding section.</p>
<p>Next, lets use the id we just created, and set it as the value of the 'id' attribute. Then we create an anchor element (<code>&lt;a&gt;</code>) with an <code>href</code> attribute pointing to the generated <code>id</code>. The anchor text is set to the text content of the <code>h2</code> element.</p>
<p>Now, we can create a list item (<code>&lt;li&gt;</code>) containing the previously created anchor element and then that list item is appended as HTML to the end of the unordered list (<code>ul</code>).</p>
<h3 id="heading-make-the-toc-interactive">Make the ToC interactive</h3>
<p>Alright, we're halfway up there! Right now, we have a dynamic Table of Contents that automatically lists all the <code>h2</code> elements with their bookmark links.</p>
<p>Now, we just have the interactive part left. We want our link to get highlighted when the corresponding section is in the page view.</p>
<p>So, now that <code>aside</code> element is populated and contains anchor tag, we will store all those anchors and name it <code>tocAnchors</code>.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> tocAnchors = aside.querySelectorAll(<span class="hljs-string">"a"</span>);
</code></pre>
<p>Next, we will declare an arrow function named, <code>obFunc</code> which will later be used in Intersection Observer. Intersection Observer is basically an API that is provided by the browser. It lets us observe the changes in the intersection of the elements we want with the document viewport or the root element of your choice.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> obFunc = <span class="hljs-function">(<span class="hljs-params">entries</span>) =&gt;</span> {}
</code></pre>
<p>Now, we have defined a function <code>obFunc</code> that takes an array of <code>entries</code> as its parameter. The function will be executed whenever the observed elements (specified later) intersect with the viewport.</p>
<p>Within the <code>forEach</code> loop for <code>entries</code>, we check if an observed element is intersecting with the viewport. If the condition is satisfied, then we find the index of the intersecting element (represented by <code>entry.target</code>) within the <code>headings</code> array.</p>
<pre><code class="lang-js">entries.forEach(<span class="hljs-function">(<span class="hljs-params">entry</span>) =&gt;</span> {
        <span class="hljs-keyword">if</span> (entry.isIntersecting) {
            <span class="hljs-keyword">const</span> index = headings.indexOf(entry.target);
        }
}
</code></pre>
<p>Using a new <code>forEach</code> loop, we iterate through all anchor elements (<code>tocAnchors</code>) and removes the "active" class from each of them so that the <code>active</code> class doesn't persist on more than one element at one time.</p>
<pre><code class="lang-js">tocAnchors.forEach(<span class="hljs-function">(<span class="hljs-params">tab</span>) =&gt;</span> {
    tab.classList.remove(<span class="hljs-string">"active"</span>);
});
</code></pre>
<p>And, now we add the <code>active</code> class to the anchor element that is intersecting at that moment. In addition to that, we use the <code>scrollIntoView</code> method that scrolls the page to bring the active anchor element into view. The option <code>{ block: "nearest" }</code> ensures that it scrolls to the nearest position both vertically and horizontally.</p>
<pre><code class="lang-js">tocAnchors[index].classList.add(<span class="hljs-string">"active"</span>);
    tocAnchors[index].scrollIntoView({
        <span class="hljs-attr">block</span>: <span class="hljs-string">"nearest"</span>
});
</code></pre>
<p>Now, we define an object, <code>oboption</code> that will act as a config for Intersection Oberserver. <code>rootMargin</code> specifies the margins around the root (in this case, the viewport), and <code>threshold</code> sets the threshold at which the callback function is triggered.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> obOption = {
    <span class="hljs-attr">rootMargin</span>: <span class="hljs-string">"-30px 0% -77%"</span>,
    <span class="hljs-attr">threshold</span>: <span class="hljs-number">1</span>
};
</code></pre>
<p>The <code>rootMargin</code> option is very important here. You're basically setting a pesudo-viewport by creating an offset from the original viewport. This becomes the surveillance area (sort of).</p>
<p>This option takes values the same way margin does – except when we use negative values here, it accounts for it by moving towards the center of the screen. You can definitely use same values as mine and achieve an ideal area, or you can play around with the values until you get your ideal behavior.</p>
<p>At last, all we have to do is create a new Intersection Observer instance with the previously defined function (<code>obFunc</code>) as callback and options (<code>obOption</code>). And then we'll use the <code>forEach</code> loop to iterate over all the <code>H2</code> elements and put them on observation using <code>.observe()</code> method.</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> observer = <span class="hljs-keyword">new</span> IntersectionObserver(obFunc, obOption);
headings.forEach(<span class="hljs-function">(<span class="hljs-params">hTwo</span>) =&gt;</span> observer.observe(hTwo));
</code></pre>
<p>When any of these elements intersect with the viewport, the <code>obFunc</code> callback function will be executed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/11/Screen-Recording-2023-11-13-at-3.22.45-PM--online-video-cutter.com-.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Project demo showing the ToC on the right while we scroll the text</em></p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>Now, you have a fully interactive and dynamic Table of Contents. Hope this tutorial helped you. Let me know if you can build upon this or improvise further on this project. Cheers!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use map(), filter(), and reduce() in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ If you want to learn React, it's important to get a fair understanding of some core JavaScript concepts first. So if that's what you're doing, first of all – great job! You have made a wise decision by not starting directly with React. Second, React ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/map-filter-reduce-in-javascript/</link>
                <guid isPermaLink="false">66d45dda868774922c884fd7</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bhavesh Rawat ]]>
                </dc:creator>
                <pubDate>Mon, 03 Oct 2022 22:06:51 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/fCC-blog-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you want to learn React, it's important to get a fair understanding of some core JavaScript concepts first.</p>
<p>So if that's what you're doing, first of all – great job! You have made a wise decision by not starting directly with React.</p>
<p>Second, React builds on key concepts like the map(), filter(), and reduce() JavaScript methods (after all – React is a JavaScript library). So this makes these methods a must-learn.</p>
<p>Map, filter, and reduce are three of the most useful and powerful high-order array methods. In this tutorial, you'll see how each of these high-order array methods work. You'll also learn where you'll want to use them and how to use them, with the help of analogies and examples. It’ll be fun!</p>
<h2 id="heading-how-to-use-the-map-method">How to Use the <code>map()</code> Method</h2>
<p>Suppose you have an array <code>arrOne</code> where you’ve stored some numbers, and you’d like to perform some calculations on each of them. But you also <strong>don’t want to mess with the original array</strong>.</p>
<p>This is where <code>map()</code> comes into the picture. The <code>map</code> method will help you do this:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> arrOne = [<span class="hljs-number">32</span>, <span class="hljs-number">45</span>, <span class="hljs-number">63</span>, <span class="hljs-number">36</span>, <span class="hljs-number">24</span>, <span class="hljs-number">11</span>]
</code></pre>
<p>map() takes a maximum of three arguments, which are value/element, index, and array.</p>
<pre><code class="lang-javascript">arrOne.map(value/element, index, array)
</code></pre>
<p>Let’s say you want to multiply each element by 5 while not changing the original array.</p>
<p>Here's the code to do that:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> arrOne = [<span class="hljs-number">32</span>, <span class="hljs-number">45</span>, <span class="hljs-number">63</span>, <span class="hljs-number">36</span>, <span class="hljs-number">24</span>, <span class="hljs-number">11</span>]
<span class="hljs-keyword">const</span> multFive = <span class="hljs-function">(<span class="hljs-params">num</span>) =&gt;</span> {
<span class="hljs-keyword">return</span> num * <span class="hljs-number">5</span>; <span class="hljs-comment">//'num' here, is the value of the array.</span>
}
<span class="hljs-keyword">let</span> arrTwo = arrOne.map(multFive)
<span class="hljs-built_in">console</span>.log(arrTwo)
</code></pre>
<p>And here's the output:</p>
<pre><code class="lang-js">[ <span class="hljs-number">160</span>, <span class="hljs-number">225</span>, <span class="hljs-number">315</span>, <span class="hljs-number">180</span>, <span class="hljs-number">120</span>, <span class="hljs-number">55</span> ]
</code></pre>
<p>So what's going on here? Well, I have an <code>arrOne</code> array with 6 elements in it. Next, I initialized an arrow function <code>multFive</code> with ‘num’ as an argument. This returns the product of <code>num</code> and 5, where the ‘num’ variable is fed the data by the map() method.</p>
<p>If you’re new to arrow functions but are familiar with regular functions, an arrow function is the same as this:</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">num</span>) 
    </span>{  
        <span class="hljs-keyword">return</span> num * <span class="hljs-number">5</span>;
    }
</code></pre>
<p>Then, I initialized another variable <code>arrTwo</code> that will store the new array that the map() method will create.</p>
<p>On the right-hand side, I called the map() method on the ‘arrOne’ array. So, the map() method will pick each value of that array starting from the index[0] and perform the desired calculation on each value. Then it'll form a new array with the calculated values.</p>
<p><strong>Important</strong>: Notice how I’m stressing not changing the original array. That is because this property is what makes the map() method different from the ‘forEach()’ method. The map() method makes a new array whereas the ‘forEach()’ method mutates/changes the original array with the calculated array.</p>
<h2 id="heading-how-to-use-the-filter-method">How to Use the <code>filter()</code> Method</h2>
<p>The name kind of gives it away, doesn't it? You use this method to filter the array based on conditions you provide. The filter() method also creates a new array.</p>
<p><strong>Let’s take an example</strong>: Suppose you have an array <code>arrName</code> and that array stores a bunch of numbers. Now, you would like to see what numbers can be divided by 3 and make a separate array from them.</p>
<p>Here's the code to do that:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> arrNum = [<span class="hljs-number">15</span>, <span class="hljs-number">39</span>, <span class="hljs-number">20</span>, <span class="hljs-number">32</span>, <span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">22</span>]
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">divByFive</span>(<span class="hljs-params">num</span>) </span>{
  <span class="hljs-keyword">return</span> num % <span class="hljs-number">3</span> == <span class="hljs-number">0</span>
}
<span class="hljs-keyword">let</span> arrNewNum = arrNum.filter(divByFive)
<span class="hljs-built_in">console</span>.log(arrNewNum)
</code></pre>
<p>And here's the output:</p>
<pre><code class="lang-js">[ <span class="hljs-number">15</span>, <span class="hljs-number">39</span>, <span class="hljs-number">30</span>, <span class="hljs-number">45</span> ]
</code></pre>
<p>Let's break down this code. Here, I have an array <code>arrNum</code> with 7 elements in it. Next, I initialized a function <code>divByFive</code> with ‘num’ as an argument. It returns true or false for each time a new num is passed for the comparison, where the ‘num’ variable is fed the data by the filter() method.</p>
<p>Then, I initialized another variable <code>arrNewNum</code> that will store the new array that the filter() method will create.</p>
<p>On the right-hand side, I called the filter() method on the <code>arrNum</code> array. So, the filter() method will pick each value of that array starting from the index[0] and perform the operation on each value. Then it'll form a new array with the calculated values.</p>
<h2 id="heading-how-to-use-the-reduce-method">How to Use the reduce() Method</h2>
<p>Let’s say you are asked to find the sum of all elements of an array. Now, you could use a for loop or the forEach() method, but reduce is built for this kind of task.</p>
<p>The <code>reduce()</code> method reduces an array to a single value by performing the desired operation on the elements collectively.</p>
<p>Let’s take the above example and use reduce on it:</p>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> arrNum = [<span class="hljs-number">15</span>, <span class="hljs-number">39</span>, <span class="hljs-number">20</span>, <span class="hljs-number">32</span>, <span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">22</span>]
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sumOfEle</span>(<span class="hljs-params">num, ind</span>) </span>{
  <span class="hljs-keyword">return</span> num + ind;
}
<span class="hljs-keyword">let</span> arrNum2 = arrNum.reduce(sumOfEle)
<span class="hljs-built_in">console</span>.log(arrNum2)
</code></pre>
<p>Here's the output:</p>
<p><code>203</code></p>
<p>Everything is the same as the map() and filter() methods – but what’s important to understand is how the reduce method works under the hood.</p>
<p>There’s not a definite <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#syntax">syntax</a> of the reduce() method. Let’s see the simplest one and that will give you the gist of all the ways you can use reduce().</p>
<p>Here's some example syntax for <code>reduce()</code>:</p>
<pre><code class="lang-js"><span class="hljs-comment">//Taking the above array for an example</span>
<span class="hljs-keyword">let</span> arrNum = [<span class="hljs-number">15</span>, <span class="hljs-number">39</span>, <span class="hljs-number">20</span>, <span class="hljs-number">32</span>, <span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">22</span>]arr.reduce(<span class="hljs-function">(<span class="hljs-params">a1, a2</span>) =&gt;</span> { 
 <span class="hljs-keyword">return</span> a1 + a2
})
</code></pre>
<p>Take a look at this syntax. Here, reduce is taking two arguments, <code>a1</code> and <code>a2</code>, where <code>a1</code> acts as an accumulator while the <code>a2</code> has the index value.</p>
<p>Now, on the first run the accumulator is equal to zero and <code>a2</code> holds the first element of the array. What reduce does is that it throws the value in the accumulator that a2 holds and increments it to the next one. After that, the reduce() method performs the operation on both operands. In this case it is addition.</p>
<p>So, basically <code>a1</code> is the accumulator which is currently zero and <code>a2</code> holds 15. After the first run, the accumulator has 15 in it and <code>a2</code> is holding the next value which is 39.</p>
<p>So, <code>0 + 15 = 15</code></p>
<p>Now, on second run, reduce throws <code>a2</code>’s value, 39 in the accumulator and then performs the operation on both operands.</p>
<p>So, <code>15 + 39 = 54</code></p>
<p>Now, on the third run, the accumulator has a sum of 15 and 39 which is 54. <code>a2</code> now holds 20 which the reduce method throws at the accumulator which sums up to <code>54 + 20 = 74</code>.</p>
<p>This process keeps on going until the end of the array.</p>
<h2 id="heading-signing-off">Signing Off</h2>
<p>Well, that’s it, everyone! Hope you have a good idea of how these high-order array methods work now. Consider sharing if you had a good time reading it and find it helpful.</p>
<p>Check out my latest story <a target="_blank" href="https://medium.com/geekculture/5-reasons-why-you-should-invest-in-a-vpn-90e95e9524fe">here</a>, and for my Git eBook, check <a target="_blank" href="https://bhaveshrawat.gumroad.com/l/lets-git-it-beginners-guide-to-git-bash-commands">here</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Useful HTML5 Tags You Might Not Know ]]>
                </title>
                <description>
                    <![CDATA[ One of the key factors that differentiates HTML 5 from its predecessors is the introduction of semantic tags. Semantic tags add real meaning to the webpage and make it easy for humans, and search engines, to differentiate between different parts of t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/html5-tags-you-might-not-know/</link>
                <guid isPermaLink="false">66d45dd83dce891ac3a967be</guid>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Bhavesh Rawat ]]>
                </dc:creator>
                <pubDate>Wed, 31 Aug 2022 21:47:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/five-html-tags-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>One of the key factors that differentiates HTML 5 from its predecessors is the introduction of semantic tags.</p>
<p>Semantic tags add real meaning to the webpage and make it easy for humans, and search engines, to differentiate between different parts of the website.</p>
<p>To a certain extent, it affects the SEO of a webpage, too.</p>
<p>So to reap the benefits, you should know the HTML5 tags you can use to enhance your website.</p>
<p>There are some very useful but little-known HTML5 tags that can come in handy, too. They give a semantic meaning to your webpage, bring more accessibility, and make your life easier.</p>
<p>Here is my list of 5 helpful HTML tags that you might wanna try.</p>
<h2 id="heading-the-tag">The <code>&lt;abbr&gt;</code> Tag</h2>
<p>You use this tag when you want to show the full form of an abbreviation you've used in your blog.</p>
<p>For example, if you're writing an article about a smart home product that also has some AI features that you want to discuss. Now, there could be some casual readers that might be unfamiliar with AI. Using this <code>abbr</code> tag coupled with the 'title' attribute will show the readers a tooltip with the content written in the title tag of the abbreviation. When the user hovers over the abbreviation, it can help them learn what "AI" means.</p>
<p>Think of how much hassle it would save you if you ever feel like adding this kind of functionality to your blog. Instead of fiddling with CSS, all you have to do is insert this tag.</p>
<h3 id="heading-how-the-tag-works">How the <code>&lt;abbr&gt;</code> tag works</h3>
<p>Considering you're writing a blog and have access to the HTML view. You have to wrap the abbreviated word with <code>&lt;abbr&gt;</code> with a title attribute which will contain the definition or a full form of the abbreviated word. When done right, the tooltip will appear when the user hovers over the abbreviation showing the content the 'title' attribute holds.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-family: sans-serif;"</span>&gt;</span> Can <span class="hljs-tag">&lt;<span class="hljs-name">abbr</span> <span class="hljs-attr">title</span>=<span class="hljs-string">"Artificial Intelligence"</span>&gt;</span>AI<span class="hljs-tag">&lt;/<span class="hljs-name">abbr</span>&gt;</span> be taught how to reciprocate human emotions?
<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-300.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-the-tag-1">The <code>&lt;details&gt;</code> Tag</h2>
<p>You use this tag to create an interactive container box that can expand and shrink when the user clicks while containing all the content. Upon expanding it shows the content within, and closes as it shrinks.</p>
<p>I use this every time I have something like an 'FAQs' or 'Table of Contents' in mind. This gives you the native support of an accordion without a single bit of JS.</p>
<p>I used it recently while working on one of my sites. I built the 'Table of Contents' section using it. (You will be able to see it down below)</p>
<h3 id="heading-how-the-tag-works-1">How the <code>&lt;details&gt;</code> tag works</h3>
<p>First, we declare the <code>&lt;details&gt;</code> tag that wraps the <code>&lt;summary&gt;</code> tag and your usual content that you want the user to see when they need it. It can be anything – a form, a table, a paragraph, or an image.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">details</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">summary</span>&gt;</span>Table of Contents<span class="hljs-tag">&lt;/<span class="hljs-name">summary</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#web-dev"</span>&gt;</span>Web Development<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#web-dev-html"</span>&gt;</span>HTML<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#web-dev-css"</span>&gt;</span>CSS<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">details</span>&gt;</span>
</code></pre>
<p>Now, I mentioned the <code>&lt;summary&gt;</code> tag earlier: this tag is used with the <code>&lt;details&gt;</code> tag and specifies a heading for the content.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/details.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Image Credit: Screen Grab of</em> <a target="_blank" href="https://freemiumstuffings.blogspot.com/2022/05/a-beefy-curated-list-of-valuable-twitter-threads.html"><em>Freemium Stuff</em></a></p>
<p><strong>Tip</strong>: Say you're making a FAQ section with this tag, and you want the container to open on page load for, like, 'The most asked question'. You can do that by just giving an 'open' attribute to that particular accordion. Like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">details</span> <span class="hljs-attr">open</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">summary</span>&gt;</span>How do I get my product registered?<span class="hljs-tag">&lt;/<span class="hljs-name">summary</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>You can get your product...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">details</span>&gt;</span>
</code></pre>
<h2 id="heading-the-tag-2">The <code>&lt;optgroup&gt;</code> Tag</h2>
<p>This tag will let you categorize the options of the drop-down list in the forms you build.</p>
<p>When you want something like a drop-down list from which users can choose, use the <code>&lt;select&gt;</code> tag. But, often it can get very long and tedious for users to go through the entire list to find the correct options.</p>
<p>Grouping the options can really help, and your users will appreciate this as they won't have to go through every option. Instead, they can just navigate through to the category they need. This makes for a better user experience.</p>
<h3 id="heading-how-the-tag-works-2">How the <code>&lt;optgroup&gt;</code> tag works</h3>
<p>Right before laying out all the options, declare the <code>&lt;optgroup&gt;</code> tag and wrap all the similar options in it, just like in the example below. You can do it for as many groups as you need.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"cars"</span>&gt;</span>Cars<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">select</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Cars"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"cars"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">optgroup</span> <span class="hljs-attr">label</span>=<span class="hljs-string">"SUV"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Porsche Cayenne<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Lincoln Nautilus<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Mercedes-Benz GLB 2022<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>BMW X3 2022<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Genesis GV80 2022<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span> 
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Mercedes-Benz GLS 2022<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">optgroup</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">optgroup</span> <span class="hljs-attr">label</span>=<span class="hljs-string">"Sports Car"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Ford Mustang<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Toyota GR Supra<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>McLaren 7205<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Porsche 911<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Audi R8 V10<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">option</span> <span class="hljs-attr">value</span>=<span class="hljs-string">""</span>&gt;</span>Chevrolet Corvette Z06<span class="hljs-tag">&lt;/<span class="hljs-name">option</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">optgroup</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">select</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-302.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Image Credit: Author</em></p>
<h2 id="heading-the-tag-3">The <code>&lt;base&gt;</code> Tag</h2>
<p>This tag will let you change the base URL for all the relative URLs in that HTML file. You should include in the <code>&lt;head&gt;</code> tag. It lets you have the convenience of the relative URLs while having the flexibility of changing the base URL.</p>
<h3 id="heading-how-the-tag-works-3">How the <code>&lt;base&gt;</code> tag works</h3>
<p>The user just needs to declare this tag inside the head tag, and now all the relative URLs in the document will get the new URL as its base.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">base</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://bhaveshrawat.pages.dev/assets/"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">figure</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 480px;"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"width: 100%;"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"netflix-planform.webp"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">figcaption</span>&gt;</span>Netflix Planform made with Grid. <span class="hljs-tag">&lt;/<span class="hljs-name">figcaption</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">figure</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">figure</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"max-width: 480px;"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"width: 100%;"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"hamburger-menu.gif"</span>&gt;</span>    
        <span class="hljs-tag">&lt;<span class="hljs-name">figcaption</span>&gt;</span><span class="hljs-symbol">&amp;lt;</span>input<span class="hljs-symbol">&amp;gt;</span> tag menu bar<span class="hljs-tag">&lt;/<span class="hljs-name">figcaption</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">figure</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-305.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-the-catch-with-the-tag">The catch with the <code>&lt;base&gt;</code> tag</h3>
<p>There's a catch with using this tag, though. It doesn't play well with in-page anchor tags, like <code>&lt;a href="#home"&gt;</code>. These types of links are pretty useful from a navigation point of view. So, unless you're doing JS to make up for the in-page anchor tags, this tag might not be ideal.</p>
<h2 id="heading-the-tag-4">The <code>&lt;map&gt;</code> Tag</h2>
<p>If you ever wanted to hook a single image with multiple links and map them according to the image, this tag will let you do exactly that.</p>
<p>This tag lets you specify the areas on an image – it can be a rectangle, circle, or poly (basically any irregular shape) – and map them to different links.</p>
<h3 id="heading-how-the-tag-works-4">How the <code>&lt;map&gt;</code> tag works</h3>
<p>First, we specify an <code>&lt;img&gt;</code> tag with the 'usemap' attribute that holds the same value as the <code>&lt;map&gt;</code> tag's name attribute. It must be the same because that will be responsible for linking the map coordinates to the image.</p>
<p>The <code>&lt;map&gt;</code> tag will be declared after that with the 'name' attribute that holds the same value as the 'usemap' attribute.</p>
<p>The <code>&lt;map&gt;</code> tag also wraps the <code>&lt;area&gt;</code> tags with 'shape', 'coords', 'alt', and 'href' attributes. The shape attribute specifies the shape of the map area, coords defines the coordinates of the map area for mapping purposes, alt is for the alternate text, and href holds the links for the respective areas.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"frame.png"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"430"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"194"</span> <span class="hljs-attr">usemap</span>=<span class="hljs-string">"#map"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">map</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"map"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"51,51,31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Twitter"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://twitter.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"161,52, 33"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Github"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://github.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"271,51,31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"LinkedIn"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://linkedin.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"379,51,31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Medium"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://medium.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"187, 143, 31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Contra"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://contra.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"215, 143, 31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Instagram"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.instagram.com/"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">area</span> <span class="hljs-attr">shape</span>=<span class="hljs-string">"circle"</span> <span class="hljs-attr">coords</span>=<span class="hljs-string">"323,143,31"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Codepen"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://codepen.io"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">map</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/APNG-1.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-one-more-thing">One more thing...</h3>
<p>This isn't a tag, but is rather an attribute that can help you in building a custom context menu for your app. I'm talking about the 'oncontextmenu' attribute.</p>
<p>The context menu is basically a menu bar that appears when the user right-clicks on the browser and is served with options like 'Inspect', 'View page source' to name a few.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/7ecce6cb9af145cb11c57bc6ccb47e1a2c0c5eac.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>While building a web-app, you might want to serve your user with a custom context menu with a bunch of special options and features, much like Spotify does.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-313.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Image Credit: Screen Grab from Spotify</em></p>
<h3 id="heading-how-the-oncontextmenu-attribute-works">How the <code>oncontextmenu</code> attribute works</h3>
<p>The value of this attribute is true by default. This lets you access the context menu that appears when you right-click. But, when given a false value the context menu will not appear.</p>
<p>So, you're disabling the native context menu because your users won't need it. Also, then it won't interfere with your web-app's functionality.</p>
<p>You don't want your custom menu to be overlapped/interfered with by the native context menu, right? So, this exercise could save you from this horrible experience.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span> <span class="hljs-attr">oncontextmenu</span>=<span class="hljs-string">"return false"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>Note: The attribute is applicable on all HTML elements. This means that if you don't want a user to have context menu functionality on a certain section only, you can do that, too. Just use the attribute on the parent element, like this</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">oncontextmenu</span>=<span class="hljs-string">"return false"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<h2 id="heading-signing-off">Signing Off</h2>
<p>So, these were the HTML tags I wanted to share with you all! I hope this article was worth your time and you learned something from it.</p>
<p>If any of these tags have piqued your interest, you can learn more about them on MDN.</p>
<p>Have a good day!</p>
<p>If you're learning Git or getting into it, I would like to recommend an e-Book that I wrote when I was learning Git. It is available in PDF and E-PUB format, you can get it for free on <a target="_blank" href="https://bhaveshrawat.gumroad.com/l/lets-git-it-beginners-guide-to-git-bash-commands">Gumroad</a>. Hope you enjoy the e-Book.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
