<?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>Forem: Sephjoe</title>
    <description>The latest articles on Forem by Sephjoe (@sephjoe12).</description>
    <link>https://forem.com/sephjoe12</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%2F1711779%2Fd4248e7d-de3f-4daa-8b24-c18ed35a150b.jpeg</url>
      <title>Forem: Sephjoe</title>
      <link>https://forem.com/sephjoe12</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sephjoe12"/>
    <language>en</language>
    <item>
      <title>Step-by-Step Tutorial: Create a React Vite Project in 7 Easy Steps</title>
      <dc:creator>Sephjoe</dc:creator>
      <pubDate>Thu, 18 Jul 2024 09:15:22 +0000</pubDate>
      <link>https://forem.com/sephjoe12/step-by-step-tutorial-create-a-react-vite-project-in-6-easy-steps-f8c</link>
      <guid>https://forem.com/sephjoe12/step-by-step-tutorial-create-a-react-vite-project-in-6-easy-steps-f8c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the past, Create React App was the go-to tool for building React applications. However, it had a major drawback: it significantly slowed down the build and development time, making it take longer to develop the server or reflect file changes.&lt;/p&gt;

&lt;p&gt;This issue is now a thing of the past. Thanks to Vite, you can easily set up your React application and reduce the wait time for your file changes to be updated.&lt;/p&gt;

&lt;p&gt;Vite , pronounced as "Veet," is a faster and lightweight way to easily build up your React applications. It was introduced in 2020 by the Vue.js creator, Evan You.&lt;/p&gt;

&lt;p&gt;In this article, you would learn how to setup your React Application and start your development server.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ensure you have Node.Js installed on your system, if you don't, visit &lt;a href="https://nodejs.org/en/download/package-manager" rel="noopener noreferrer"&gt;Node.Js&lt;/a&gt; official website to install the package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A basic knowledge on how to use the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Code editor or IDE (prefferably VS code for this tutorial).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps for Setting up a React project with Vite
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a New Folder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Navigate to File Explorer or Finder if you are on a Mac, and create a new folder. Then, open that folder in your text editor. In this tutorial, we will be using VS Code as our text editor.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a New React Vite Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open your terminal and type the following command prompt to create a new React Vite Project.&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm create vite@latest &amp;lt;project-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above example, The "&amp;lt;project name&amp;gt;" is important because it will be the directory name where Vite sets up your project structure. You can use any name of your choice. In this tutorial, we will use "React-Project".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Select your Framework&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You'll be presented with a list of frameworks. Use the arrow keys to navigate and select React.&lt;br&gt;&lt;br&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%2F0ylxb1hbnk3lraa3sokq.jpeg" 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%2F0ylxb1hbnk3lraa3sokq.jpeg" alt="List of Framework options in Vite"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Select your Variant&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Choose the language or transpiler of your choice. In this tutorial, we're using JavaScript.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&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%2Fgqacdwl0zfmvq8xa5h2s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgqacdwl0zfmvq8xa5h2s.jpg" alt="List of Variant Options in Vite"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running this command successfully, you should have a project structure containing all your files and resources, the project structure should look like this.&lt;br&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%2Fp8ecimt88nmoaawyhbso.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp8ecimt88nmoaawyhbso.jpg" alt="React Vite Project Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5  &lt;strong&gt;Change Directory into Your Folder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the next command to change the directory into the folder we created, "React-app".&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; cd "React-Project"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;6 &lt;strong&gt;Install Dependencies&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Run the following command to install your project dependencies. &lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;7 &lt;strong&gt;Start Project&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To view your website live in your browser, enter the following command.&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Next, you will receive a link like this &lt;a href="http://localhost:5173/" rel="noopener noreferrer"&gt;http://localhost:5173&lt;/a&gt; with a default port of 5173 . Click on the link to view your application in your browser. You should see a display like the one below.&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%2Fk5spj8hpr7dhjkmhhl9j.jpeg" 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%2Fk5spj8hpr7dhjkmhhl9j.jpeg" alt="React Vite Live Application"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;In this article, you successfully learned how to set up a new React project with Vite. Vite provides a faster way of setting up your development environment compared to Create-React-App. I hope you build more React apps with Vite in the future. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript Loops for Beginners: Learn the Basics</title>
      <dc:creator>Sephjoe</dc:creator>
      <pubDate>Wed, 17 Jul 2024 18:44:03 +0000</pubDate>
      <link>https://forem.com/sephjoe12/javascript-loops-for-beginners-learn-the-basics-jhk</link>
      <guid>https://forem.com/sephjoe12/javascript-loops-for-beginners-learn-the-basics-jhk</guid>
      <description>

&lt;p&gt;It's a gloomy Monday, and you are at work. We all know how depressing Mondays can be, right? Your boss approaches you and says, "Hey, I have 300 unopened emails we've received over the weekend. I want you to open each one, write down the sender's name, and delete the emails once you're done."&lt;/p&gt;

&lt;p&gt;This task looks very tiring if you try to do it manually. The next thing on your mind is probably to get on Google and look for software that can automate this process and make your life easier, right?&lt;/p&gt;

&lt;p&gt;Well, we have similar situations in programming. There are times when you need to perform repeated tasks until they're done. How do you solve this issue? In JavaScript, we have what we refer to as loops. Loops allow us to solve repeated tasks by reducing the amount of code needed to complete the task.&lt;/p&gt;

&lt;p&gt;In this article, we'll discuss what a loop is, how it works, and the various methods we can use to apply it in our programs.&lt;/p&gt;

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

&lt;p&gt;Loops are used in JavaScript to perform repeated actions easily. They are based on a condition that returns true or false.&lt;/p&gt;

&lt;p&gt;A condition is an expression that must be passed to keep a loop running. A loop runs when the specified conditions returns a true value and stops when they return a false value.&lt;/p&gt;

&lt;h2&gt;
  
  
  When do you need to use a loop?
&lt;/h2&gt;

&lt;p&gt;Loops are useful for carrying out repetitive tasks. For example, using a loop shortens the code needed to solve a problem. It saves time, optimizes memory usage, and improves flexibility.&lt;/p&gt;

&lt;p&gt;A loop true significance extends beyond reducing code length and limiting repetition. They also help when working with data in an array, object, or other structures. Moreover, loops promote code modularity by reducing repetitive code and increasing code reusability, which makes it possible to create codes that can be used within different parts of your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of loops
&lt;/h2&gt;

&lt;p&gt;There are two major categories of loops: entry-controlled loops and exit-controlled loops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entry-controlled&lt;/strong&gt; loops evaluate the condition at the "entrance of the loop" before executing the loop's body. If the condition is true, the body runs. If not, the body doesn't run. The for and while loops are examples of entry-controlled loops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exit-controlled&lt;/strong&gt; loops focus on the loop's body over the test condition, ensuring that the loop's body is executed at least once before evaluating the test condition. A good example of an Exit-controlled loop is the do-while loop.&lt;/p&gt;

&lt;p&gt;Let's examine some examples of entry-controlled loops:&lt;/p&gt;

&lt;h3&gt;
  
  
  while Loop
&lt;/h3&gt;

&lt;p&gt;A while loop has the following syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (condition) {
  //  loop's body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The following list explains the functionality of a while loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The while loop takes a test condition inside parentheses.&lt;/li&gt;
&lt;li&gt;The program checks the condition to see whether it passes or fails.&lt;/li&gt;
&lt;li&gt;The code within the loop's body executes as long as the condition is passed.&lt;/li&gt;
&lt;li&gt;The program terminates its operation once the test condition fails.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Below, let's take a practical example on the while loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let arr = [];
let i = 1;
let number = 5;

while (i &amp;lt;= number) {
arr.push(i)
i++
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The code snippet above initializes the "arr", "i", and "num" variables.&lt;/li&gt;
&lt;li&gt;The "arr" variable is an array that holds the values that pass the test condition.&lt;/li&gt;
&lt;li&gt;The "i" variable keeps track of each increment after each iteration. &lt;/li&gt;
&lt;li&gt;The "number" variable compares the value of "i" to it value (5) after each iteration.&lt;/li&gt;
&lt;li&gt;The code within the loop's body pushes each value of "i" after each iteration into the array as long as "i" is less than or equal to "number".&lt;/li&gt;
&lt;li&gt;Once the current value of "i" fails the condition, in this case, where the value of "i" is greater than "number" which is 6, the loop stops running.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;push()&lt;/code&gt; method is a built-in JavaScript function that adds a new item to the end of an array.&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 2, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  do-while Loop
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;do-while&lt;/code&gt;loop closely resembles the while loop; the main difference between the &lt;code&gt;while&lt;/code&gt; and the &lt;code&gt;do-while&lt;/code&gt;loop is that the &lt;code&gt;do-while&lt;/code&gt; loop ensures code execution at least once before evaluating the loop's condition, the &lt;code&gt;do-while&lt;/code&gt; loop has the following syntax below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {
  // loop's body
}
while (//condition)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;do-while&lt;/code&gt; is an excellent example of an exit-controlled loop. This lies in the fact that exit-controlled loops give priority to the loop's body before the test condition, now let's delve into a practical code example utilizing the do-while loop.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i = 1;
let num = 5;

do {
  console.log(i);
  i++;
} while (i &amp;lt;= num);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's break down this code snippet:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We initialized the "i" and "num" variables.&lt;/li&gt;
&lt;li&gt;The console logs in the value of "i" (1) before evaluating the loop's condition.&lt;/li&gt;
&lt;li&gt;The condition is checked, and the value of "i" increments with +1 after each iteration.&lt;/li&gt;
&lt;li&gt;The loop ends its operation once "i" is greater than "num".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although the &lt;code&gt;do-while&lt;/code&gt; loop is very much similar to the &lt;code&gt;while&lt;/code&gt; loop, there are subtle differences we must note, let’s take another example that compares the difference between the while and do-while loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let i = 5;
let num = 4

while( i &amp;lt; num)
{
  console.log(i)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;while&lt;/code&gt; loop above won't return any result to the console, now why is this so?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We initialized the "i" and "num" variables with values of 5 and 4, respectively.&lt;/li&gt;
&lt;li&gt;The condition checks if the value of "i" is less than "num".&lt;/li&gt;
&lt;li&gt;If true, it logs in each respective value.&lt;/li&gt;
&lt;li&gt;Since the initial value of "i" exceeds that of "num", the loop never runs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;now let's take a similar example with the &lt;code&gt;do-while&lt;/code&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let i = 5;
let num = 4;

do {
  console.log(i)
}
while ( i &amp;lt; num)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;do-while&lt;/code&gt; loop ensures the execution of the code block, which returns 5 into the console, although "i" has a higher value than "num" initially, it's still logged in the console once. This representation shows you the difference in functionality between the &lt;code&gt;do-while&lt;/code&gt; and &lt;code&gt;while&lt;/code&gt; loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  For loop
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;for loop&lt;/code&gt; is a unique type of loop and one of the most commonly used loop by programmers, the &lt;code&gt;for loop&lt;/code&gt; is a loop that runs a code block for a specific number of time depending on a condition. The &lt;code&gt;for loop&lt;/code&gt; has the following syntax below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (Expression1...; Expression2....; Expression3...{
     //code block
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expression1: This part of a &lt;code&gt;for loop&lt;/code&gt; is also known as the initialization area, it's the beginning of our &lt;code&gt;for loop&lt;/code&gt; and the area where the counter variable is defined; the counter variable is used to track the number of times the loop runs and store that as a value.&lt;/p&gt;

&lt;p&gt;Expression2: This is the second part of the loop, this part defines the conditional statement that would execute the loop.&lt;/p&gt;

&lt;p&gt;Expression3: This is where the loop ends; the counter variable in this section updates its value after each iteration either by increasing or decreasing the value as specified in the condition.&lt;/p&gt;

&lt;p&gt;Let's dive into an example using the &lt;code&gt;for loop&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; 100; i++) {
    console.log("Hello World" )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the code snippet above, let's break it down together.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, we've initialized the counter variable "i" with a value of zero.&lt;/li&gt;
&lt;li&gt;Next, we've created the conditional statement that would keep the code running.&lt;/li&gt;
&lt;li&gt;We compared the value of "i" with 100, if it passes this test, "Hello World" is logged.&lt;/li&gt;
&lt;li&gt;This process repeats while the counter increases with +1 after each iteration.&lt;/li&gt;
&lt;li&gt;The loop ends once the counter's value reaches 100.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello World
Hello World
Hello World

...

//repeated 97 more times making it 100 "Hello World" in total
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  for-each loop
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;for-each&lt;/code&gt; loop is a method in JavaScript that travels through an array and applies a callback function on each element in that array; a callback function is simply another function passed as a parameter into a function, the callback function works by running sequentially after the main function is done executing.&lt;/p&gt;

&lt;p&gt;Let's examine the basic syntax of a for-each loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
array.forEach(function(currentValue, index, arr))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The provided code above explains the workings of a for-each loop.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This loop accepts three parameters, which are the current value, an index, and an array.&lt;/li&gt;
&lt;li&gt;The current value represents the present value of the element in the array.&lt;/li&gt;
&lt;li&gt;The index is an optional parameter that tells you the numbered position of the current element in that array.&lt;/li&gt;
&lt;li&gt;The arr is another optional parameter that tells you what array the element belongs to.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let myArray = [1, 2, 3, 4, 5];

array.forEach((num, index, arr) =&amp;gt; {
  arr[index] = num * 2;

  console.log(array);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break down the example above:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We initialized an array with the variable name "myArray" and stored it with integers ranging from 1 to 5.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;for-each&lt;/code&gt; array method takes three parameters and applies a callback function on the array.&lt;/li&gt;
&lt;li&gt;This line; &lt;code&gt;arr[index] = num * 2&lt;/code&gt; multiplies the value of the current element by 2 and assigns the returned value to the current element's index.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Take note, the &lt;code&gt;for-each&lt;/code&gt; array method does not return a new array; rather, it modifies the original array and returns it.&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, 4, 6, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What are for... in and for... of loops in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;for... in&lt;/code&gt; and &lt;code&gt;for... of&lt;/code&gt; loops are very useful when it comes to iterating over iterable objects, iterable objects refers to any element that is capable of being looped over, common examples of iterables objects are arrays, strings, sets, etc.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;for... in&lt;/code&gt; and for... of are similar in how they iterate/move through objects, the main difference between them is shown on how they return values.&lt;/p&gt;

&lt;h3&gt;
  
  
  for... in loops
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;for... in&lt;/code&gt; loop is useful when you need to extract the key(s)/properties from an object and it corresponding properties from the parent object, the for... in loop at times might iterate through an object in a manner that is different from the way it was defined in that particular object, let's take an example of a for... in loop in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let namesArray = [];

const studentScores = {
John: 60,
Dan: 53,
Tricia: 73,
Jamal: 45,
Jane: 52
}

for(const name in studentScores){
  namesArray.push(name);
}

console.log(namesArray);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we have defined an object named studentScores that contains several student names and their corresponding scores, by using for... in, we were able to retrieve only the names of the students, which represent the keys of the object studentScores, and store them in an array by using the push() method.&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
["John", "Dan", "Tricia", "Jamal", "Jane"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  for... of loops
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;for... of&lt;/code&gt; loop is a special type of loop that iterates over the values of iterable objects such as arrays, strings, maps, e.t.c., &lt;code&gt;for... of&lt;/code&gt; loops does not concern itself with the keys or properties of an object, rather it shows priorities on the values only, the &lt;code&gt;for... of&lt;/code&gt; loop is unable to iterate over regular objects and will throw an error since they are not iterable. Let's take an example using the &lt;code&gt;for.. of&lt;/code&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numArray = [1,2,3,4,5]

for (const value of numArray) {
    console.log(value)
}

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

&lt;/div&gt;



&lt;p&gt;// Output =  1,2,3,4,5&lt;br&gt;
In summary, the &lt;code&gt;for... in&lt;/code&gt; and &lt;code&gt;for... of&lt;/code&gt; loops are great way to loop through iterable objects, the main difference is a &lt;code&gt;for... in&lt;/code&gt; loop returns the key of an Object while the &lt;code&gt;for... of&lt;/code&gt; loop returns only the values of iterable objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an infinite loop and how can we avoid it?
&lt;/h2&gt;

&lt;p&gt;An infinite loop refers to a loop that continues to run indefinitely; this occurs when a loop has no defined exit condition. Infinite loops are dangerous because they can crash your browser and lead to unwanted actions in your program.&lt;/p&gt;

&lt;p&gt;// infinite loop sample&lt;br&gt;
while (true) {&lt;br&gt;
 console.log("keep on running")&lt;br&gt;
}&lt;br&gt;
To prevent infinite loops in your program, always ensure that there is an exit condition defined within your loop.&lt;/p&gt;

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

&lt;p&gt;Thank you very much for getting to the end of this article, loops in Javascript are important concept every developer needs to master as it is very valuable to creating a good and optimizable program, I believe with this article you would be able to understand the basics and intricacies of using loops in your program.&lt;/p&gt;

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