<?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: Sagar Kumar Shrivastava</title>
    <description>The latest articles on DEV Community by Sagar Kumar Shrivastava (@sinhasagar01).</description>
    <link>https://dev.to/sinhasagar01</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%2F365866%2F3577d51f-0f30-436e-afe2-403fd68a3411.jpeg</url>
      <title>DEV Community: Sagar Kumar Shrivastava</title>
      <link>https://dev.to/sinhasagar01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sinhasagar01"/>
    <language>en</language>
    <item>
      <title>Closure in JavaScript</title>
      <dc:creator>Sagar Kumar Shrivastava</dc:creator>
      <pubDate>Sun, 28 Dec 2025 14:26:27 +0000</pubDate>
      <link>https://dev.to/sinhasagar01/closure-in-javascript-3bfh</link>
      <guid>https://dev.to/sinhasagar01/closure-in-javascript-3bfh</guid>
      <description>&lt;h2&gt;
  
  
  What is Closure?
&lt;/h2&gt;

&lt;p&gt;To truly understand &lt;strong&gt;closures&lt;/strong&gt; in JavaScript, we first need to understand how JavaScript executes code under the hood.&lt;/p&gt;

&lt;p&gt;Closures are not a separate feature, they are a natural result of how &lt;strong&gt;Execution Contexts&lt;/strong&gt; and &lt;strong&gt;Lexical Environments&lt;/strong&gt; work.&lt;/p&gt;

&lt;p&gt;Let's break this down step by step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Execution Context
&lt;/h2&gt;

&lt;p&gt;Whenever a function is invoked, JavaScript creates a new &lt;strong&gt;Execution Context&lt;/strong&gt; for that function.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;Execution Contexts&lt;/strong&gt; fundamentally consists of two main components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variable Environment (Memory Component)&lt;/li&gt;
&lt;li&gt;Lexical Environment (Scope Resolution Component)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Variable Environment (Memory Component)
&lt;/h3&gt;

&lt;p&gt;This is where the function's local data is stored.&lt;/p&gt;

&lt;p&gt;Before a single line of code is executed, the JavaScript engine scans the function and allocates memory for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Variables declared&lt;/strong&gt; using &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function declarations&lt;/strong&gt; (entire function definitions)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arguments object&lt;/strong&gt;, which contains all values passed to the function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This setup happens during the &lt;strong&gt;Creation Phase&lt;/strong&gt; of the &lt;strong&gt;Execution Context&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Lexical Environment (Scope Resolution Component)
&lt;/h3&gt;

&lt;p&gt;This component is responsible for executing the code line by line and resolving variables.&lt;/p&gt;

&lt;p&gt;It contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scope Chain&lt;/strong&gt;&lt;br&gt;
A reference to the parent's Lexical Environment. This is how JavaScript looks up variables that are not present in the current scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;this&lt;/code&gt; binding&lt;/strong&gt;&lt;br&gt;
The value of &lt;code&gt;this&lt;/code&gt;, determined by how the function is called.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Two Phases of Execution Context
&lt;/h3&gt;

&lt;p&gt;Every Execution Context is created in two phases:&lt;/p&gt;

&lt;p&gt;1️⃣ Creation Phase&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory is allocated&lt;/li&gt;
&lt;li&gt;Variables are hoisted&lt;/li&gt;
&lt;li&gt;Functions are stored entirely&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; exist in the Temporal Dead Zone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2️⃣ Execution Phase&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code runs line by line&lt;/li&gt;
&lt;li&gt;Variables receive their actual values&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Let's Understand This with an Example
&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%2F9jitp8qp5ejqjo6oi4dy.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%2F9jitp8qp5ejqjo6oi4dy.png" alt="Code for Closure" width="800" height="694"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Global Execution Context (GEC)
&lt;/h4&gt;

&lt;p&gt;Before any code runs, JavaScript creates the Global Execution Context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;outer&lt;/code&gt; → stored as a function&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fn&lt;/code&gt; → initialized as &lt;code&gt;undefined&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Execution Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The engine reaches &lt;code&gt;const fn = outer()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;This triggers the creation of a &lt;strong&gt;new Execution Context&lt;/strong&gt; for &lt;code&gt;outer()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&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%2Fmrj6d0xeln04ae51c3j4.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%2Fmrj6d0xeln04ae51c3j4.png" alt="Global Execution Context (GEC)" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: &lt;code&gt;outer()&lt;/code&gt; Execution Context
&lt;/h4&gt;

&lt;p&gt;When &lt;code&gt;outer()&lt;/code&gt; is called, its &lt;strong&gt;Execution Context&lt;/strong&gt; is pushed onto the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; is allocated (in TDZ because it’s declared with let)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;inner&lt;/code&gt; function is created and stored entirely&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Execution Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; is assigned the value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;inner&lt;/code&gt; function is returned&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Termination&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;outer()&lt;/code&gt; Execution Context is popped off the Call Stack&lt;/li&gt;
&lt;/ul&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%2Fe01g96g6314rjxp2i78u.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%2Fe01g96g6314rjxp2i78u.png" alt="Outer Execution Context" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⚠️ Crucial Detail (This is the key to Closure)&lt;br&gt;
Even though the &lt;code&gt;outer()&lt;/code&gt; Execution Context is destroyed, its &lt;strong&gt;Lexical Environment is NOT garbage collected&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because the returned function inner still holds a reference to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👉 This preserved reference is what we call a Closure.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: fn() Execution Context (First Call)
&lt;/h4&gt;

&lt;p&gt;At this point:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const fn = outer();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fn&lt;/code&gt; now holds a reference to the &lt;code&gt;inner&lt;/code&gt; function along with its hidden &lt;code&gt;[[Environment]]&lt;/code&gt; link to &lt;code&gt;outer’s&lt;/code&gt; Lexical Environment.&lt;/p&gt;

&lt;p&gt;When we call:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fn();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No local variables&lt;/li&gt;
&lt;li&gt;Empty arguments object&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Execution Phase&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count++&lt;/code&gt; is executed&lt;/li&gt;
&lt;li&gt;JavaScript looks for &lt;code&gt;count&lt;/code&gt; in &lt;code&gt;fn&lt;/code&gt;’s local scope → not found&lt;/li&gt;
&lt;li&gt;It follows the Scope Chain to &lt;code&gt;outer&lt;/code&gt;’s Lexical Environment&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; is found with value &lt;code&gt;0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It is incremented to &lt;code&gt;1&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1&lt;/code&gt; is returned&lt;/li&gt;
&lt;/ul&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%2Fc88s275gt1yppzcu8gfv.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%2Fc88s275gt1yppzcu8gfv.png" alt="Fn Execution Context" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  So, What is a Closure?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A Closure is formed when a function "remembers" the variables from its lexical scope even after that scope's execution context has finished.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Closures happen because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Functions carry a hidden reference (&lt;code&gt;[[Environment]]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;This reference points to the Lexical Environment where the function was created&lt;/li&gt;
&lt;li&gt;As long as the function exists, that environment stays alive&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Mental Model 🧠
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;🔑 Closure is not about function execution, it's about function creation.&lt;br&gt;
A function remembers the lexical environment where it was defined, even after that environment's execution context is gone.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Higher Order Function in JavaScript</title>
      <dc:creator>Sagar Kumar Shrivastava</dc:creator>
      <pubDate>Thu, 25 Dec 2025 12:44:58 +0000</pubDate>
      <link>https://dev.to/sinhasagar01/higher-order-function-in-javascript-5867</link>
      <guid>https://dev.to/sinhasagar01/higher-order-function-in-javascript-5867</guid>
      <description>&lt;p&gt;In my &lt;a href="https://dev.to/sinhasagar01/functions-5bab"&gt;last post&lt;/a&gt;, we solved the &lt;strong&gt;"pain of the century"&lt;/strong&gt; by using &lt;strong&gt;parameters as placeholders&lt;/strong&gt; for our &lt;strong&gt;data&lt;/strong&gt;. We learned that we don't need a &lt;strong&gt;fiveSquared&lt;/strong&gt; and a &lt;strong&gt;sixSquared&lt;/strong&gt; function; we just need one &lt;code&gt;calculateSquare(num)&lt;/code&gt; function where &lt;code&gt;num&lt;/code&gt; acts as a &lt;code&gt;placeholder&lt;/code&gt; for any value.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But we are still facing a tiny bit of &lt;strong&gt;"pain."&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Right now, our function is a specialist. It only knows how to &lt;strong&gt;square&lt;/strong&gt; a number. But what if we want a function that is a generalist? What if we want to pass in a number and then decide if we want to square it, cube it, or even just double it?&lt;/p&gt;

&lt;p&gt;In this article, we are diving into &lt;strong&gt;Higher-Order Functions&lt;/strong&gt;. This is where we stop just passing data (like numbers and strings) into functions and start passing operations (other functions) as placeholders.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;And if you're wondering how a function can be passed as a parameter in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The short answer:&lt;/p&gt;

&lt;p&gt;In JavaScript, functions are &lt;strong&gt;first-class citizens&lt;/strong&gt;.&lt;br&gt;
That means a &lt;strong&gt;function is just a value&lt;/strong&gt;, like a &lt;strong&gt;number&lt;/strong&gt; or a &lt;strong&gt;string&lt;/strong&gt;, so it can be passed as a parameter to another function.&lt;br&gt;
The function being passed as an &lt;strong&gt;argument&lt;/strong&gt; is often called a &lt;strong&gt;"Callback Function"&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we are diving into &lt;strong&gt;Higher-Order Functions&lt;/strong&gt;. This is where we stop just passing data (like numbers and strings) into functions and start passing &lt;strong&gt;operations&lt;/strong&gt; (other functions) as placeholders.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Quick Analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it like this: If a standard parameter is a placeholder for the ingredients, a &lt;strong&gt;Higher-Order Function&lt;/strong&gt; allows us to leave a placeholder for the recipe itself!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The "Master Machine" Example
&lt;/h2&gt;

&lt;p&gt;Check out this code. Notice how &lt;code&gt;doMath&lt;/code&gt; doesn't know if it's &lt;strong&gt;adding&lt;/strong&gt; or &lt;strong&gt;multiplying&lt;/strong&gt; yet, it waits for us to tell it what to do!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. We define our "Mini-Machines" (Operations)
const square = (n) =&amp;gt; n * n;
const double = (n) =&amp;gt; n * 2;

// 2. We define our "Master Machine" (The Higher-Order Function)
// 'operation' is the placeholder for the logic we want to use!
function doMath(num, operation) {
    return operation(num);
}

// 3. Now we can change the logic on the fly!
console.log(doMath(5, square)); // Output: 25
console.log(doMath(5, double)); // Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why this is a game-changer:
&lt;/h2&gt;

&lt;p&gt;Do you see what happened there? We didn't have to write a &lt;code&gt;doSquare&lt;/code&gt; function and a &lt;code&gt;doDouble&lt;/code&gt; function. Instead, we wrote one Master Function (&lt;code&gt;doMath&lt;/code&gt;) and left a placeholder for the &lt;strong&gt;operation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is the ultimate level of the &lt;strong&gt;DRY&lt;/strong&gt; principle. Now, we aren't just reusing data; we are reusing the entire structure of our code and simply swapping out the logic whenever we feel like it. No more &lt;strong&gt;"pain of the century"&lt;/strong&gt;, just clean, flexible code!&lt;/p&gt;

&lt;p&gt;The concept of &lt;strong&gt;Higher-Order Function&lt;/strong&gt; is very important in &lt;strong&gt;JavaScript&lt;/strong&gt; and its most popular frameworks like &lt;strong&gt;React&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;If you haven't understood it yet or want to understand what problem Higher-Order Function is solving by analogy, then read further:&lt;/p&gt;

&lt;h2&gt;
  
  
  The Power Tool Analogy: Attachments vs. Machines
&lt;/h2&gt;

&lt;p&gt;Imagine you are working on a construction project.&lt;/p&gt;

&lt;p&gt;If you followed the "old way" (our fixed functions), you would have to buy a completely different, heavy machine for every single task. - You'd have one machine that only &lt;strong&gt;drills&lt;/strong&gt;, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one machine that only &lt;strong&gt;sands&lt;/strong&gt;, and &lt;/li&gt;
&lt;li&gt;one machine that only &lt;strong&gt;saws&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you ran out of room in your truck, that would be the &lt;strong&gt;"pain of the century!"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Higher-Order Functions are like a Power Drill.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The drill itself doesn't know what it's going to do yet. It just provides the power and the rotation. To make it useful, you plug in an attachment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Plug in a &lt;strong&gt;drill bit&lt;/strong&gt;, and you're making holes.&lt;/li&gt;
&lt;li&gt;Plug in a &lt;strong&gt;sanding disc&lt;/strong&gt;, and you're smoothing wood.&lt;/li&gt;
&lt;li&gt;Plug in a &lt;strong&gt;screwdriver head&lt;/strong&gt;, and you're fixing a cabinet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this scenario:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Drill&lt;/strong&gt; is your &lt;strong&gt;Higher-Order Function&lt;/strong&gt;. It’s the &lt;strong&gt;"Master Machine&lt;/strong&gt;" that handles the work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Attachment&lt;/strong&gt; is the &lt;strong&gt;Callback Function&lt;/strong&gt; (the operation). It's the specific logic you swap in and out.&lt;/li&gt;
&lt;li&gt;The Wood is your Data. It's the material you are working on.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By using this approach, you don't need to reinvent the &lt;strong&gt;"power"&lt;/strong&gt; every time. You just change the &lt;strong&gt;attachment&lt;/strong&gt; to change the &lt;strong&gt;operation&lt;/strong&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: From Manual Labor to Master Engineering
&lt;/h2&gt;

&lt;p&gt;We've come a long way from the &lt;strong&gt;"pain of the century."&lt;/strong&gt; We started with functions that were stuck doing one thing forever, moved to functions that could handle different data, and now we've mastered &lt;strong&gt;Higher-Order Functions&lt;/strong&gt;, the power drills of the JavaScript world.&lt;/p&gt;

&lt;p&gt;By using placeholders for both your data and your logic, you are no longer just writing code; you are building systems. You've learned that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parameters&lt;/strong&gt; make your data flexible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Callbacks&lt;/strong&gt; make your operations flexible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Higher-Order Functions&lt;/strong&gt; bring it all together to keep your code &lt;strong&gt;DRY&lt;/strong&gt; and professional&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next time you find yourself writing the same logic over and over, stop and ask yourself: "Can I turn this into a power tool?" If the answer is yes, you're well on your way to mastering JavaScript.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>functional</category>
    </item>
    <item>
      <title>Core Premise of Function in JavaScript</title>
      <dc:creator>Sagar Kumar Shrivastava</dc:creator>
      <pubDate>Thu, 25 Dec 2025 11:39:39 +0000</pubDate>
      <link>https://dev.to/sinhasagar01/functions-5bab</link>
      <guid>https://dev.to/sinhasagar01/functions-5bab</guid>
      <description>&lt;h2&gt;
  
  
  Is this a function in JavaScript?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fiveSquared() {
    return 5 * 5
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Technically, yes.&lt;br&gt;
&lt;code&gt;fiveSquared&lt;/code&gt;, instead of technically being a function, it doesn't have all the characteristics of a real-world function: &lt;strong&gt;reusability&lt;/strong&gt;. No matter how many times you call &lt;code&gt;fiveSquared()&lt;/code&gt;, it will always return &lt;code&gt;25&lt;/code&gt;. If you suddenly need to calculate the square of &lt;code&gt;6&lt;/code&gt;, you're stuck. You would have to write a brand new function called &lt;code&gt;sixSquared&lt;/code&gt; just to do &lt;code&gt;6 * 6&lt;/code&gt;. This is the &lt;strong&gt;"pain of the century"&lt;/strong&gt;, doing the same work over and over again!&lt;/p&gt;

&lt;p&gt;Even though this code is a function, it defeats the fundamental principle of &lt;strong&gt;DRY (Don’t Repeat Yourself)&lt;/strong&gt;. A function's true purpose isn't just to &lt;code&gt;hold a calculation&lt;/code&gt;; it’s to provide a flexible logic that &lt;strong&gt;saves you from writing the same code twice&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Cure for the "Pain of the Century"
&lt;/h2&gt;

&lt;p&gt;So, how do we fix a function like &lt;code&gt;fiveSquared&lt;/code&gt; so it doesn't break the &lt;strong&gt;DRY&lt;/strong&gt; principle? We use &lt;strong&gt;Parameters&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of hardcoding the number 5 inside the logic, we create a "placeholder" (an input variable). This allows the function to stay the same, while the numbers we give it &lt;strong&gt;can change&lt;/strong&gt;. Here is the better way to do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function calculateSquare(num) {
    return num * num;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding &lt;code&gt;num&lt;/code&gt; inside the parentheses, we’ve just saved ourselves a lifetime of work! Now, we don't need to write &lt;code&gt;fiveSquared&lt;/code&gt;, &lt;code&gt;sixSquared&lt;/code&gt;, or &lt;code&gt;sevenSquared&lt;/code&gt;. We have one single function that can handle any number in the world.&lt;/p&gt;

&lt;p&gt;When we call the function like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;calculateSquare(5)&lt;/code&gt; returns &lt;strong&gt;25&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;calculateSquare(6)&lt;/code&gt; returns &lt;strong&gt;36&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;calculateSquare(100)&lt;/code&gt; returns &lt;strong&gt;10,000&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the true power of JavaScript functions. We wrote the logic &lt;strong&gt;once&lt;/strong&gt;, and now we can &lt;strong&gt;reuse it forever&lt;/strong&gt;. We finally moved away from the &lt;strong&gt;"pain"&lt;/strong&gt; of repeating ourselves and started writing &lt;strong&gt;smart&lt;/strong&gt;, &lt;strong&gt;scalable&lt;/strong&gt; code.&lt;/p&gt;

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

&lt;p&gt;Writing functions is one of the first big steps in your coding journey. It’s the difference between doing manual labor and building a machine that works for you.&lt;/p&gt;

&lt;p&gt;Remember: A great function doesn't just do a task, it provides a flexible logic that you can use over and over again without ever having to rewrite it. By using parameters and avoiding hardcoded values, you move away from the "pain of the century" and toward becoming a clean, efficient developer.&lt;/p&gt;

&lt;p&gt;Keep practicing, keep your code DRY, and most importantly, stop repeating yourself!&lt;/p&gt;

&lt;h2&gt;
  
  
  Test Your Knowledge: The Function Challenge!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Write a function called multiplyByTen that takes one parameter and returns that number multiplied by 10.&lt;/li&gt;
&lt;li&gt;What happens if you create a function with a parameter but forget to use that parameter inside the logic? Does it still follow the DRY principle?&lt;/li&gt;
&lt;li&gt;Can you write a function that takes two different parameters (like num1 and num2) and adds them together?&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this article, we discovered that we can leave a &lt;strong&gt;placeholder for data&lt;/strong&gt; (a parameter). This allows us to pass different numbers into &lt;code&gt;calculateSquare&lt;/code&gt; later on, finally making our code reusable.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But what if we could go even deeper?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the next article, we are going to learn how to leave a placeholder for the operation itself. Just like we passed in a different number, we can actually pass in a different &lt;strong&gt;action&lt;/strong&gt;(operation). Right now, our function is stuck doing &lt;strong&gt;multiplication&lt;/strong&gt;, but what if we could tell it to &lt;strong&gt;multiply&lt;/strong&gt; one day and &lt;strong&gt;add&lt;/strong&gt; the next, without changing the core function?&lt;/p&gt;

&lt;p&gt;Get ready, because we're about to learn how to make our logic just as flexible as our data by using something called &lt;a href="https://dev.to/sinhasagar01/higher-order-function-in-javascript-5867"&gt;&lt;strong&gt;Higher Order Function&lt;/strong&gt;&lt;/a&gt; (HOF for short).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>programming</category>
    </item>
    <item>
      <title>Arrays in Javascript</title>
      <dc:creator>Sagar Kumar Shrivastava</dc:creator>
      <pubDate>Thu, 27 Oct 2022 13:53:20 +0000</pubDate>
      <link>https://dev.to/sinhasagar01/arrays-in-javascript-26fh</link>
      <guid>https://dev.to/sinhasagar01/arrays-in-javascript-26fh</guid>
      <description>&lt;h2&gt;
  
  
  TOC
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is an Array?&lt;/li&gt;
&lt;li&gt;Nature of Javascript Arrays&lt;/li&gt;
&lt;li&gt;Creating Arrays&lt;/li&gt;
&lt;li&gt;Reading and Writing Array Elements&lt;/li&gt;
&lt;li&gt;Sparse Array&lt;/li&gt;
&lt;li&gt;Empty Array&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  What is an Array? &lt;a href="https://dev.towhat-is-an-Array?"&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Arrays are an ordered collection of values where each value is called an element. The index number allows us to refer to each element in the array.&lt;/p&gt;

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

&lt;p&gt; &lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Nature of Javascript Arrays &lt;a href="https://dev.tonature-of-javascript-arrays"&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JavaScript arrays are Zero-based, so the index starts at zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript arrays can contain any number of different values. It could contain a number, string, boolean, object or even another array.&lt;br&gt;
&lt;/p&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;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt; &lt;span class="p"&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="mi"&gt;4&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;p&gt;JavaScript arrays are dynamic, so we can add and remove elements from an array at any time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The total number of elements inside an array can be get or set by the length property.&lt;br&gt;
&lt;/p&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;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;43&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Elements of an array can be empty, &lt;strong&gt;&lt;em&gt;an array with empty elements is called Sparse array&lt;/em&gt;&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.tocreating-arrays"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Arrays
&lt;/h3&gt;

&lt;p&gt; &lt;br&gt;
There are various method to create Javascript Arrays. The preferred method is to use an array literal.&lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Array Literal - []&lt;/strong&gt; (preferred method)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with no value&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;arr1&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="c1"&gt;// 0&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&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="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with values&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;arr2&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="c1"&gt;// 3&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[,,,,,];&lt;/span&gt; &lt;span class="c1"&gt;// Creating a sparse array - [empty × 5]&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;arr3&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="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Array Constructor - new Array()&lt;/strong&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;arr1&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;Array&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with no value&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;arr1&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="c1"&gt;// 0&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr2&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;Array&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="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with values&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;arr2&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="c1"&gt;// 3&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr3&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;Array&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;// Creating a sparse array - [empty × 5]&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;arr3&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="c1"&gt;// 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; - If the only argument passed to the Array constructor is an integer between 0 and 232 - 1 (inclusive), this returns a new JavaScript array with its length property set to that number. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array" rel="noopener noreferrer"&gt;MDN&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;😇 Still scratching your head then use &lt;code&gt;Array.of()&lt;/code&gt; Static method. Remember these are alternative method so don't worry much about it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Array.of()&lt;/strong&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;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;of&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with no value&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;arr1&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="c1"&gt;// 0&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;of&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="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Creating an array with values&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;arr2&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="c1"&gt;// 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Array.fill()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Array.fill() will let us create the array at the same time include a value that will be in every single position/index.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For example :-&lt;/strong&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;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&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="c1"&gt;// [1, 1, 1, 1, 1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use &lt;code&gt;fill()&lt;/code&gt; method on already created arrays.&lt;br&gt;
&lt;strong&gt;For example :-&lt;/strong&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;arr2&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="nf"&gt;fill&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;// [2, 2, 2, 2, 2, 2, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can pass 3 arguments to &lt;code&gt;fill()&lt;/code&gt; method.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fill(value) - &lt;/li&gt;
&lt;li&gt;fill(value, start)&lt;/li&gt;
&lt;li&gt;fill(value, start, end) &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;value to fill the array with&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; index is optional arguments. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;start&lt;/code&gt; is inclusive. Default 0&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;end&lt;/code&gt; is exclusive, Default array.length&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;For example :-&lt;/strong&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;arr3&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="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [6, 6, 6, 4, 5, empty × 3]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.toreading-and-writing-array-elements"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reading and Writing Array Elements
&lt;/h3&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Reading elements from an array&lt;/strong&gt;&lt;br&gt;
 &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array Literal
&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;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;52&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;// 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;at()&lt;/strong&gt; method (ECMAScript 2022)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.&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;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;52&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;arr1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;at&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;// 22&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;arr1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 52&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Writing elements in an array&lt;/strong&gt;&lt;br&gt;
 &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Within the length of the 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;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;arr1&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="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;javascript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [22, 32, 42, "javascript", 52];&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;arr1&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="c1"&gt;// 5;&lt;/span&gt;

&lt;span class="nx"&gt;arr1&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="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [22, 32, 42, "javascript", 52, "tom"];&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;arr1&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="c1"&gt;// 6;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Beyond the length of the array - It creates an empty array in between.
&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="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;67&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;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [22, 32, 42, 'javascript', 52, 'tom', empty × 2, 67]&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;arr1&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="c1"&gt;// 9&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt; &lt;/p&gt;



&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.tosparse-array"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Sparse Array
&lt;/h3&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Sparse Array?&lt;/strong&gt;&lt;br&gt;
 &lt;br&gt;
A sparse array is an an array with empty elements, we can call it holes in the array. &lt;br&gt;
index of the empty element will log &lt;code&gt;undefined&lt;/code&gt; in Chrome because as Javascript doesn't have a value for the hole.&lt;br&gt;&lt;br&gt;
 &lt;br&gt;
&lt;strong&gt;Ways to create Sparse Array&lt;/strong&gt;&lt;br&gt;
 &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example 1&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the below example, we are assigning a value to an index number of 8 and there was nothing assigned to the index numbers between 5 and 8 which 6 and 7. &lt;/p&gt;

&lt;p&gt;So 6 and 7 became empty elements and therefore we have sparse array right now.&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;arr1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;67&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;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// [22, 32, 42, 'javascript', 52, 'tom', empty × 2, 67]&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;arr1&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="c1"&gt;// 9&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;arr1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;// undefined&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;arr1&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;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can create a sparse array by simply putting commas(,). Every time there is a comma that creates a new element but there is nothing in those element so it creates holes in the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&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;arr2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [empty × 6]&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;arr2&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="c1"&gt;// 6&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;arr2&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;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Example 3&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Assigning value(as number) to the length of an array and if that value is greater than the actual length of the array can create a sparse array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&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="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;8&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;arr2&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="c1"&gt;// 4&lt;/span&gt;

&lt;span class="c1"&gt;// Setting a new length which is greater than actual &lt;/span&gt;
&lt;span class="c1"&gt;// length of the array which is 4 in our case&lt;/span&gt;
&lt;span class="nx"&gt;arr2&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;10&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;arr2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [2, 3, 5, 8, empty × 6]&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;arr2&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="c1"&gt;// 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example 4&lt;/strong&gt; (using &lt;code&gt;delete&lt;/code&gt; operator on Arrays)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;delete&lt;/code&gt; doesn't modify the length of the array, it just creates the sparse array(hole in the array).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr1&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="mi"&gt;6&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="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;arr1&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;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5, empty, 7]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;




&lt;p&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Empty Array &lt;a href="https://dev.toempty-array"&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Two simple ways to empty and array.&lt;/strong&gt;&lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. - Reassigning original array to an empty array.&lt;/strong&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;let&lt;/span&gt; &lt;span class="nx"&gt;arr1&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="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This technique is not emptying the array but assigns a new empty array to it.&lt;br&gt;
 &lt;br&gt;
See the below example where &lt;code&gt;arr2&lt;/code&gt; still references the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr1&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="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;arr1&lt;/span&gt; &lt;span class="o"&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;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&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;arr2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5, 6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notice&lt;/strong&gt; - The above approach will not work with &lt;code&gt;const&lt;/code&gt; keyword because variables assigned with &lt;code&gt;const&lt;/code&gt; keyword can not be re-assigned. &lt;br&gt;
 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Setting array &lt;code&gt;length&lt;/code&gt; property to zero.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
With this technique, we will empty the original array and we can see in the below example that even &lt;code&gt;arr2&lt;/code&gt; is logging as an empty array.&lt;/p&gt;

&lt;p&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;let&lt;/span&gt; &lt;span class="nx"&gt;arr1&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="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;arr2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;arr1&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;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&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;arr2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// []&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; &lt;/p&gt;

&lt;p&gt;This is it, now you can go for a coffee break. If I have missed something along the way, do point it out in the comment box. &lt;/p&gt;

&lt;p&gt;Upcoming articles on Javascript Arrays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to iterate Arrays&lt;/li&gt;
&lt;li&gt;Working with Array-like collections&lt;/li&gt;
&lt;li&gt;Array Methods&lt;/li&gt;
&lt;li&gt;Multidimensional Arrays&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Till then, Keep Learning! 🤘&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>array</category>
    </item>
    <item>
      <title>Javascript for Absolute Beginners #01</title>
      <dc:creator>Sagar Kumar Shrivastava</dc:creator>
      <pubDate>Wed, 12 Aug 2020 22:14:43 +0000</pubDate>
      <link>https://dev.to/sinhasagar01/javascript-for-absolute-beginners-01-g52</link>
      <guid>https://dev.to/sinhasagar01/javascript-for-absolute-beginners-01-g52</guid>
      <description>&lt;p&gt; Note: I will put reference links or explain the Jargons used in this article at the bottom of the article.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;This is my first article for absolute beginners who wanted to learn Javascript from scratch, in these articles I will try to cover every tiny bit of javascript.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What is Javascript?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Javascript is a dynamic programming language.&lt;sup&gt;1&lt;/sup&gt; Javascript enables interactivity in Web pages.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Javascript Syntax&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Case Sensitive&lt;/li&gt;
&lt;li&gt;Identifiers&lt;/li&gt;
&lt;li&gt;Comments&lt;/li&gt;
&lt;li&gt;Statements&lt;/li&gt;
&lt;li&gt;Expressions&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Case Sensitive&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Javascript is a case-sensitive language. It means &lt;strong&gt;apple&lt;/strong&gt; &amp;amp; &lt;strong&gt;Apple&lt;/strong&gt; is not the same variable.&lt;sup&gt;2&lt;/sup&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;let&lt;/span&gt; &lt;span class="nx"&gt;apple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is a lowercase apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;Apple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is an uppercase apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;apple&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;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;lowercase&lt;/span&gt; &lt;span class="nx"&gt;apple&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Apple&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;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;an&lt;/span&gt; &lt;span class="nx"&gt;uppercase&lt;/span&gt; &lt;span class="nx"&gt;apple&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Identifiers&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The identifier is the name given to a variable, function&lt;sup&gt;3&lt;/sup&gt;, parameter&lt;sup&gt;4&lt;/sup&gt; by the programmer who wrote that program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;varName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This is an identifier&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// In the above example, varName is the Identifier&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rules for writing an identifier name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first character of the identifier name must start with a letter (a-z, A-Z) / (_ underscore) / ($ dollar sign)
&lt;/li&gt;
&lt;li&gt;The other character of the identifier name can be a letter (a-z, A-Z) / (0-9) / (_ underscore) / ($ dollar sign).&lt;/li&gt;
&lt;li&gt;JavaScript defines a list of keywords that have special uses. You cannot use the keywords as the identifiers. 
&lt;a href="https://www.w3schools.com/js/js_reserved.asp"&gt;See Full List of keywords&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Comments&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Comments are common practice in all programming languages for leaving notes or explaining your code to yourself and others.&lt;/p&gt;

&lt;p&gt;There are two kinds of comments in javascript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-line comment&lt;/li&gt;
&lt;li&gt;Multi-line comment or Block comment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// this is a single-line comment&lt;/span&gt;


&lt;span class="cm"&gt;/*
* This is a block comment that can
* span multiple lines
*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Statements&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Statements are a sequence of commands that needs to be executed. Statements should end with a semicolon(;), strongly recommended but not required.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Semicolon(;) is required for the readability of the code and also to avoid syntax errors&lt;sup&gt;5&lt;/sup&gt; after minifying&lt;sup&gt;6&lt;/sup&gt; javascript code.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Expressions&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;An expression is a block of code that evaluated to a value.&lt;/p&gt;

&lt;p&gt;Below are the types of Expressions in Javascript. I will explain these in the next article.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arithmetic expressions - Ex. 2 + 3&lt;/li&gt;
&lt;li&gt;String expressions - Ex. 'sagar' + 'sinha'&lt;/li&gt;
&lt;li&gt;Primary expressions - Ex. true, false&lt;/li&gt;
&lt;li&gt;Array and object initializers expressions - Ex.[], {}&lt;/li&gt;
&lt;li&gt;Logical expressions - Ex. &amp;amp;&amp;amp;, ||&lt;/li&gt;
&lt;li&gt;Left-hand-side expressions - Ex. new, super&lt;/li&gt;
&lt;li&gt;Property access expressions - Ex. object.property&lt;/li&gt;
&lt;li&gt;Object creation expressions - Ex. new object()&lt;/li&gt;
&lt;li&gt;Function definition expressions - Ex. function() {}&lt;/li&gt;
&lt;li&gt;Invocation expressions - Ex. f(0)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cheers! See you again in the next article. (Next article will be about expressions in detail.)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Jargons Explained&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic programming language&lt;/strong&gt; - In computer science, a dynamic programming language is a class of high-level programming languages, which at runtime execute many common programming behaviors that static programming languages perform during compilation. Source - Wikipedia&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Related Links for more informatiion - &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Dynamic_programming_language"&gt;mdn&lt;/a&gt; , &lt;a href="https://en.wikipedia.org/wiki/Dynamic_programming_language"&gt;wikipedia&lt;/a&gt; , &lt;a href="https://www.sitepoint.com/typing-versus-dynamic-typing/"&gt;sitepoint&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Variable&lt;/strong&gt; - Variables are named reference to a value. Further details on the variables in the coming articles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Function&lt;/strong&gt; - A function is a block of statements that are used to perform a specific task. Further details on the variables in the coming articles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Parameter&lt;/strong&gt; - Will learn in detail in an upcoming article.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Syntax errors&lt;/strong&gt; - An incorrect use of pre-defined syntax cause a syntax error. For example, if you leave off a closing brace (}) when defining a JavaScript function, you trigger a syntax error.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minifying&lt;/strong&gt; - Minifying the code means removing whitespaces, comments, and other unnecessary stuff that is not needed for the execution of the code. This process is used for reducing the file size.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you guys have any doubt or anything you haven't understood, please feel free to ask in the comment. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
