<?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: Sakib Ahmed</title>
    <description>The latest articles on Forem by Sakib Ahmed (@devvsakib).</description>
    <link>https://forem.com/devvsakib</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%2F908897%2Ff80c6aa6-fc1f-4bd1-8fc3-28e776992f65.jpg</url>
      <title>Forem: Sakib Ahmed</title>
      <link>https://forem.com/devvsakib</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/devvsakib"/>
    <language>en</language>
    <item>
      <title>Dive into Open Source: A Guide to Hacktoberfest 2023</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Fri, 13 Oct 2023 11:12:24 +0000</pubDate>
      <link>https://forem.com/devvsakib/dive-into-open-source-a-guide-to-hacktoberfest-2023-3o41</link>
      <guid>https://forem.com/devvsakib/dive-into-open-source-a-guide-to-hacktoberfest-2023-3o41</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Hey, tech enthusiasts! Are you ready for the most exciting month in the world of open source? Hacktoberfest is back and buzzing with energy for its 2023 edition! It's that time of the year when developers, designers, and tech aficionados from around the globe come together to contribute to open source projects. In this post, we'll explore what Hacktoberfest is, how you can participate, and why this annual event is so special for the tech community. Let's embark on this open source journey and make a meaningful impact!&lt;/p&gt;

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

&lt;p&gt;Hacktoberfest is an annual celebration of open source software, organized by DigitalOcean in partnership with GitHub. It's a month-long event during October, where contributors are encouraged to make at least four high-quality pull requests to open source projects. It's a fantastic way to give back to the community, improve your skills, and get some cool swag in return!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Participate:
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Sign Up:
&lt;/h4&gt;

&lt;p&gt;Create an account on the Hacktoberfest website (hacktoberfest.digitalocean.com) to officially register for the event. This is where you'll be able to track your progress throughout the month.&lt;/p&gt;

&lt;h4&gt;
  
  
  Find Projects:
&lt;/h4&gt;

&lt;p&gt;Explore the Hacktoberfest website or GitHub to discover open source projects you'd like to contribute to. Look for issues labeled as "Hacktoberfest" or "good first issue" to find beginner-friendly tasks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Fork and Clone:
&lt;/h4&gt;

&lt;p&gt;Fork the repository of the project you want to contribute to. Clone your forked repository to your local machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  Make Contributions:
&lt;/h4&gt;

&lt;p&gt;Work on the issues, fix bugs, add features, improve documentation, or whatever the project requires. Ensure your contributions meet the project's guidelines.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create Pull Requests:
&lt;/h4&gt;

&lt;p&gt;Submit pull requests to the original repository. Describe your changes, and if the project maintainers are satisfied, your pull requests will be merged!&lt;/p&gt;

&lt;h4&gt;
  
  
  Track Progress:
&lt;/h4&gt;

&lt;p&gt;Check your progress on the Hacktoberfest website as you complete your contributions. Remember, you need to make at least four valid pull requests to complete the challenge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hacktoberfest Matters:
&lt;/h2&gt;

&lt;p&gt;Hacktoberfest is more than just a challenge—it's a celebration of collaboration, innovation, and learning. By participating, you're contributing to the open-source ecosystem and helping make software better for everyone. It's an opportunity to learn from experienced developers, gain exposure to diverse projects, and develop skills that will shape your tech journey.&lt;/p&gt;

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

&lt;p&gt;Join the global community in celebrating Hacktoberfest 2023! Let's come together, learn, grow, and contribute to the open source world. Make your mark, have fun, and let's create a lasting impact on the software development landscape. Happy Hacking!&lt;/p&gt;

&lt;h1&gt;
  
  
  hacktoberfest2023 #hacktoberfest23
&lt;/h1&gt;

</description>
      <category>hacktoberfest23</category>
      <category>hacktoberfest</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to solve Vercel and Netlify "Page Not Found" after page refresh [SOLVED]</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Mon, 27 Feb 2023 16:25:12 +0000</pubDate>
      <link>https://forem.com/devvsakib/how-to-solve-vercel-and-netlify-page-not-found-after-page-refresh-solved-2ol7</link>
      <guid>https://forem.com/devvsakib/how-to-solve-vercel-and-netlify-page-not-found-after-page-refresh-solved-2ol7</guid>
      <description>&lt;p&gt;Worst Worst Worst. What?&lt;/p&gt;

&lt;p&gt;You obviously deployed your React App in vercel or netlify right? If you are using &lt;code&gt;react-router&lt;/code&gt; then you must face the shitty &lt;strong&gt;Page Not Found&lt;/strong&gt; page.&lt;/p&gt;

&lt;p&gt;Netlify not found page&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%2F42ev1pm7nvhs1u8a28ns.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%2F42ev1pm7nvhs1u8a28ns.png" alt="devvsakib article"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why this page shows us when we don't like it? Huh, there are a simple reason for this. When you use a React Router in your application and navigate to another page and reload your site, it give as "Page Not Found". Even, your 404 page doesn't work. Am I right? Let me know in the comment below.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to solve this?
&lt;/h2&gt;

&lt;p&gt;To fix this error whenever you are either trying to access your app or you're on other routes, you have to set up a redirect and rewrite rules for your react-router application. The redirect rule will help your application avoid "Page Not Found". &lt;/p&gt;

&lt;p&gt;I will show you both in vercel and netlify. 1 shot 2 Kill.&lt;/p&gt;

&lt;h2&gt;
  
  
  For NETLIFY
&lt;/h2&gt;

&lt;p&gt;Add a &lt;code&gt;_redirects&lt;/code&gt; file in your public folder. In my case, I'm using react + vite. I added &lt;code&gt;_redirects&lt;/code&gt; file in the public folder.&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%2F62l1j88s4v64r2qbq7x5.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%2F62l1j88s4v64r2qbq7x5.png" alt="devvsakib"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now copy paste this code to &lt;code&gt;_redirects&lt;/code&gt; file.&lt;br&gt;
&lt;code&gt;/* /index.html 200&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Boom, done.&lt;/p&gt;

&lt;h2&gt;
  
  
  For VERCEL
&lt;/h2&gt;

&lt;p&gt;Create a file named &lt;code&gt;vercel.json&lt;/code&gt; in the root folder of your project.&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%2Ffy7zx3v2da21kxi9trpg.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%2Ffy7zx3v2da21kxi9trpg.png" alt="devvsakib"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;now again copy paste.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"rewrites"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/(.*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"destination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


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

&lt;/div&gt;

&lt;p&gt;Boom, done x2&lt;/p&gt;

&lt;h3&gt;
  
  
  result?
&lt;/h3&gt;

&lt;p&gt;My 404 page working😵&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%2F3xrzzbmmf1uz5yisej3f.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%2F3xrzzbmmf1uz5yisej3f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;after navigating to another page and refresh, my website working&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%2Fsaq8682f0xyh9g21q08j.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%2Fsaq8682f0xyh9g21q08j.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey, we manage to throw vercel and netlify "&lt;strong&gt;Page Not Found&lt;/strong&gt;", show some support🤗&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>netlify</category>
      <category>vercel</category>
      <category>react</category>
    </item>
    <item>
      <title>Web Development Internship at Oasis Infobyte: A Learning Journey</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Mon, 13 Feb 2023 18:25:02 +0000</pubDate>
      <link>https://forem.com/devvsakib/web-development-internship-at-oasis-infobyte-a-learning-journey-11dp</link>
      <guid>https://forem.com/devvsakib/web-development-internship-at-oasis-infobyte-a-learning-journey-11dp</guid>
      <description>&lt;p&gt;As a web development enthusiast, I was excited to embark on a journey of learning and growth with Oasis Infobyte, a leading web development company. I was fortunate enough to secure a month-long internship in February and it turned out to be a fantastic experience. I was able to complete 3 tasks of level 2 and hone my skills in web development.&lt;/p&gt;

&lt;p&gt;The team at Oasis Infobyte was incredibly supportive and provided me with opportunities to work on real-life projects. This gave me a hands-on experience of how web development works in the real world. I was amazed at the level of professionalism and expertise the team had in their respective fields. I was able to learn a great deal from my colleagues and was amazed by how willing they were to share their knowledge and experiences with me.&lt;/p&gt;

&lt;p&gt;One of the highlights of my internship was being able to work on various projects and tasks. I was able to apply the knowledge and skills I had acquired and develop my abilities further. I was particularly proud of completing 3 tasks of level 2 and contributing to the overall success of the projects I worked on.&lt;/p&gt;

&lt;p&gt;The training I received at Oasis Infobyte was unparalleled. I was introduced to various technologies, tools that are used in web development. I was able to learn about front-end development and more. The knowledge and skills I acquired during my internship have been invaluable and will help me in my future endeavors.&lt;/p&gt;

&lt;p&gt;In conclusion, my web development internship at Oasis Infobyte was an unforgettable experience. I am grateful for the opportunity to work with such a fantastic team and learn from some of the best in the field. I would highly recommend Oasis Infobyte to anyone looking to start or advance their web development career. For more information, visit their website at oasisinfobyte.com.&lt;/p&gt;

&lt;p&gt;You can also connect with me on &lt;a href="//https:github.com/devvsakib"&gt;Github&lt;/a&gt;and &lt;a href="https://twitter.com/DevvSakib" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; to keep up with my web development journey and follow my future endeavors. Beside I have &lt;/p&gt;

&lt;p&gt;Thank you for the opportunity to share my experience and I look forward to the next chapter in my web development journey.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Git &amp; GitHub Common Error</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Sun, 22 Jan 2023 09:16:38 +0000</pubDate>
      <link>https://forem.com/devvsakib/git-github-common-error-oke</link>
      <guid>https://forem.com/devvsakib/git-github-common-error-oke</guid>
      <description>&lt;h2&gt;
  
  
  GitHub ERROR SOLVE - GES
&lt;/h2&gt;

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

&lt;p&gt;GES stands for GitHub Error Solve. This is an Open Source project dedicated to resolving any errors or issues that may arise while using GitHub. Our primary objective is to empower individuals to feel comfortable and confident using the platform by providing comprehensive solutions to common problems.&lt;/p&gt;

&lt;p&gt;This website was created to help newbie users who want to use GitHub and git with joy but don't want to face the same error or issues. Here I added all the common errors you may face while using Git and GitHub. Feel free to check it out. Hope this website will help.&lt;/p&gt;

&lt;p&gt;Tech Stack:&lt;/p&gt;

&lt;p&gt;React, Vite, Tailwind&lt;/p&gt;

&lt;p&gt;If you want to work on this project, you are very welcome.&lt;/p&gt;

&lt;p&gt;Find your problem here by typing the error:&lt;/p&gt;

&lt;p&gt;Live: &lt;a href="https://github-error-solve.vercel.app" rel="noopener noreferrer"&gt;https://github-error-solve.vercel.app&lt;/a&gt;&lt;br&gt;
Repo: &lt;a href="https://github.com/devvsakib/github-error-solve" rel="noopener noreferrer"&gt;https://github.com/devvsakib/github-error-solve&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>A HTTPRequest article by generated by ChatGPT!</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Mon, 26 Dec 2022 12:34:53 +0000</pubDate>
      <link>https://forem.com/devvsakib/a-httprequest-article-by-generated-by-chatgpt-5dn5</link>
      <guid>https://forem.com/devvsakib/a-httprequest-article-by-generated-by-chatgpt-5dn5</guid>
      <description>&lt;p&gt;This http request article generated by ChatGPT!&lt;/p&gt;

&lt;p&gt;HTTP (Hypertext Transfer Protocol) is a protocol that is used for communication between a client and a server on the World Wide Web. It allows clients (e.g. a web browser) to send requests to servers (e.g. a web server) and receive responses in return.&lt;/p&gt;

&lt;p&gt;There are several different types of HTTP requests that can be made, including &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;, and others. Each type of request serves a different purpose and is used in different scenarios.&lt;/p&gt;

&lt;p&gt;Here is a brief overview of the most common types of HTTP requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GET&lt;/strong&gt;: A &lt;code&gt;GET&lt;/code&gt; request is used to retrieve information from a server. It is the most common type of request and is used to retrieve a webpage or other resource.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;POST&lt;/strong&gt;: A &lt;code&gt;POST&lt;/code&gt; request is used to send data to a server for processing. It is typically used when a user submits a form or uploads a file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;PUT&lt;/strong&gt;: A &lt;code&gt;PUT&lt;/code&gt; request is used to update an existing resource on the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DELETE&lt;/strong&gt;: A &lt;code&gt;DELETE&lt;/code&gt; request is used to delete a resource from the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To make an HTTP request in JavaScript, you can use the &lt;code&gt;XMLHttpRequest&lt;/code&gt; object or the &lt;code&gt;fetch()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Here is an example of an HTTP &lt;code&gt;GET&lt;/code&gt; request using &lt;code&gt;XMLHttpRequest&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create an instance of the XMLHttpRequest object&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;xhr&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;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Set the request method, URL, and other options&lt;/span&gt;
&lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://www.example.com/somefile.txt&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="c1"&gt;// Send the request&lt;/span&gt;
&lt;span class="nx"&gt;xhr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is an example of an HTTP &lt;code&gt;GET&lt;/code&gt; request using &lt;code&gt;fetch()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Send the request&lt;/span&gt;
&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://www.example.com/somefile.txt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle the response&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These examples demonstrate how to make a simple GET request, but you can use other request methods (e.g. &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;) by setting the &lt;code&gt;open()&lt;/code&gt; method's third argument accordingly.&lt;/p&gt;

&lt;p&gt;HTTP requests are an essential part of web development and are used to retrieve and send data between clients and servers. Whether you are using XMLHttpRequest or fetch(), understanding how to make HTTP requests is an important skill for any frontend developer.&lt;/p&gt;

&lt;p&gt;Finish here ------------&lt;/p&gt;

&lt;p&gt;So, this one just a small blog. You can even create script for your video, generate any type of blog! Besides, If you worked with WordPress, you surely know what is plugin. Fact is, you also able to create plugin with chatGPT and you dont even need to write a single line of code. Sound wired?&lt;/p&gt;

&lt;p&gt;If you feel lonely, chat with chatGPT.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>State vs Props in reactjs</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Sat, 03 Dec 2022 15:36:40 +0000</pubDate>
      <link>https://forem.com/devvsakib/state-vs-props-in-reactjs-3e9n</link>
      <guid>https://forem.com/devvsakib/state-vs-props-in-reactjs-3e9n</guid>
      <description>&lt;h3&gt;
  
  
  What is State?
&lt;/h3&gt;

&lt;p&gt;The state is an update-able structure that is used to contain data or information about the component and can change over time. The change in state can happen as a response to user action or system event. &lt;strong&gt;It is the heart of the react component which determines the behavior of the component and how it will render&lt;/strong&gt;. A &lt;strong&gt;state&lt;/strong&gt; must be kept as simple as possible. It represents the component's local state or information. it can only be accessed or modified inside the component or by the component directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Props?
&lt;/h3&gt;

&lt;p&gt;Props are read-only component. It is an object which stores the value of attributes of a tag and work similar to the HTML attributes. It allows passing data from one component to other components. It is similar to function arguments and can be passed to the component the same way as arguments passed in a function. Props are &lt;strong&gt;immutable&lt;/strong&gt; so we cannot modify the props from inside the component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dissimilarity between State and Props
&lt;/h3&gt;

&lt;p&gt;1.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State changes can be asynchronous.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props are read-only.&lt;/p&gt;

&lt;p&gt;2.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State is mutable.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props are immutable.&lt;/p&gt;

&lt;p&gt;3.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State holds information about the components.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props allow you to pass data from one components to other components as an argument.&lt;/p&gt;

&lt;p&gt;4.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State can be used for rendering dynamic changes with the component.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props used to communicate between components.&lt;/p&gt;

&lt;p&gt;5.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State cannot be accessed by child components.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props can be accessed by child components.&lt;/p&gt;

&lt;p&gt;6.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; The state is internal and controlled by the React Component itself.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props are external and controlled by what ever renders the component.&lt;/p&gt;

&lt;p&gt;7.&lt;br&gt;
&lt;strong&gt;State:&lt;/strong&gt; State cannot make components reusable.&lt;br&gt;
&lt;strong&gt;Props:&lt;/strong&gt; Props make components reusable.&lt;/p&gt;

&lt;p&gt;Below table will guide you about the changing in props and state.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;NO&lt;/th&gt;
        &lt;th&gt;Condition&lt;/th&gt;
        &lt;th&gt;State&lt;/th&gt;
      &lt;th&gt;Props&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;1.&lt;/td&gt;
        &lt;td&gt;Can get initial value from parent component?&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;2.&lt;/td&gt;
        &lt;td&gt;Can be changed by parent Component?&lt;/td&gt;
        &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;3.&lt;/td&gt;
        &lt;td&gt;Can set default values inside component?&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
  &lt;tr&gt;
        &lt;td&gt;4.&lt;/td&gt;
        &lt;td&gt;Can change inside component?&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;5.&lt;/td&gt;
        &lt;td&gt;Can set initial value for child component?&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;tr&gt;
        &lt;td&gt;6.&lt;/td&gt;
        &lt;td&gt;Can change in child component?&lt;/td&gt;
        &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And last but not least, The component state and props share some common similarities. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;NO&lt;/th&gt;
        &lt;th&gt;State and Props&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;1.&lt;/td&gt;
        &lt;td&gt;Both are plain JavaScript Object.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;2.&lt;/td&gt;
        &lt;td&gt;Both can contain default values.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;3.&lt;/td&gt;
        &lt;td&gt;Both are read-only when they are using this.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;See yaaa. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/devvsakib" rel="noopener noreferrer"&gt;devvsakib &lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>What is SCOPE in JavaScript?</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Tue, 29 Nov 2022 18:39:19 +0000</pubDate>
      <link>https://forem.com/devvsakib/what-is-scope-in-javascript-17ed</link>
      <guid>https://forem.com/devvsakib/what-is-scope-in-javascript-17ed</guid>
      <description>&lt;p&gt;It's all about accessing variable. The accessibility or validity of a variable is determined by it's &lt;strong&gt;SCOPE&lt;/strong&gt;.&lt;br&gt;
Suppose a variable is declared inside a function. And you try to access the variable outside that function. &lt;br&gt;
Then you will encounter an error that the variable is not defined.&lt;/p&gt;

&lt;p&gt;Ex:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb93pyx7kyseouzs8o5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgb93pyx7kyseouzs8o5b.png" alt="example of not defined variable" width="713" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But Why?&lt;/strong&gt;&lt;br&gt;
Because the &lt;strong&gt;scope&lt;/strong&gt; of that variable is limited to that function and you can't access that.&lt;/p&gt;
&lt;h3&gt;
  
  
  Scope type
&lt;/h3&gt;

&lt;p&gt;There are two types of scope in javascript.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Local Scope&lt;/li&gt;
&lt;li&gt;Global Scope&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwkz9vwom5jwj7kg1276.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwkz9vwom5jwj7kg1276.png" alt="scope in javascript" width="645" height="320"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Local Scope.
&lt;/h3&gt;

&lt;p&gt;Whenever a variable is declared inside a &lt;strong&gt;function&lt;/strong&gt; it is said to have &lt;strong&gt;local scope&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;A variable declared inside a function can only be used inside that function. We can't access it outside the function&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Global Scope.
&lt;/h3&gt;

&lt;p&gt;The variable which can be accessed everywhere are said to have &lt;strong&gt;global scope&lt;/strong&gt;. These variable are not declared inside any function.&lt;/p&gt;

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

&lt;p&gt;A global variable can be accessed by any function.&lt;br&gt;
Here, we assigned value of a variable which is outside the function.&lt;/p&gt;

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

&lt;p&gt;In the above snippet, we have a variable &lt;strong&gt;globalScope&lt;/strong&gt; whose scope is not limited to any function and thus can be accessed everywhere, even within a function&lt;/p&gt;

&lt;p&gt;You are done, but wait...&lt;/p&gt;

&lt;p&gt;There are something call &lt;strong&gt;Hoisting&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Hoisting
&lt;/h4&gt;

&lt;p&gt;In &lt;strong&gt;JavaScript&lt;/strong&gt;, all variable declarations are moved to the top of their scope. This is known is &lt;strong&gt;hoisting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In JavaScript, a variable can be used before it is declared! wait what? yes, read it right.&lt;/p&gt;

&lt;p&gt;I mean that:&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;var&lt;/span&gt; &lt;span class="nx"&gt;newVar&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="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;newVar&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will result the same output, because all the variable are automatically moved to top when we run the program. &lt;/p&gt;

&lt;p&gt;This concept is known as &lt;strong&gt;hoisting&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;A &lt;strong&gt;scope&lt;/strong&gt; of a variable is the block where it can be accessed and used.&lt;/p&gt;

&lt;p&gt;If a variable is declared inside a &lt;strong&gt;function&lt;/strong&gt; it is known as a &lt;strong&gt;local variable&lt;/strong&gt;.&lt;br&gt;
If a variable is declared globally, it is said to have a &lt;strong&gt;global scope&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hoisting&lt;/strong&gt; is a JavaScript's behaviour of moving variable declarations to the top.&lt;/p&gt;

&lt;p&gt;See yaa...&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Tips: Array destructuring in javascript ES6</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Mon, 28 Nov 2022 17:48:43 +0000</pubDate>
      <link>https://forem.com/devvsakib/tips-array-destructuring-in-javascript-es6-3clg</link>
      <guid>https://forem.com/devvsakib/tips-array-destructuring-in-javascript-es6-3clg</guid>
      <description>&lt;p&gt;The following invokes the &lt;code&gt;getScore()&lt;/code&gt; function and assigns the returned value to a variable.&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;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getScore&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get the invidual score, you need to do like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&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="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;scores&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Prior to ES6, there was no direct way to assign the elements of the array to multiple variables such as x, y and z.&lt;/p&gt;

&lt;p&gt;But in ES6, you can use the destructing assignment as follow:&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getScore&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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&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;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable x, y and z will take the values of the first second third elements of the array.&lt;/p&gt;

&lt;p&gt;*Note that the square brackets [ ] look like the array syntax but they are not.&lt;/p&gt;

&lt;p&gt;If array return two elements, the third varible z will be &lt;code&gt;undefined&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getScore&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getScore&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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&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;z&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;p&gt;But if array has more than three element, the remaining elements are discarded. Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getScore&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="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;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getScore&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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&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;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there are a cool way to catch them ;)&lt;/p&gt;

&lt;h3&gt;
  
  
  Array Destructuring Assigment and REST syntax
&lt;/h3&gt;

&lt;p&gt;It's possible to take all remaining elements of an array and put them in a new array bu using the &lt;em&gt;rest&lt;/em&gt; syntax (...):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getScore&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="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;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getScore&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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&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;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 30&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;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [40, 50]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember, rest return a new array with remaining elements.&lt;/p&gt;

&lt;p&gt;Note: it's possible to destructure an array in the assingment that separates from the variable's declaration. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="p"&gt;]&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="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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 10&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;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Intro to JS array destructuring
&lt;/h3&gt;

&lt;p&gt;Suppose, you have a function that returns an array of numbers as follows:&lt;/p&gt;

&lt;h3&gt;
  
  
  Nested array destructuring
&lt;/h3&gt;

&lt;p&gt;The following function returns an array that contains an element or nested 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;getProfile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Since the third element of the returned array is another array, you have to use the nested array destructuring suntax to destructure it, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;color1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color3&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getProfile&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;color1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;color3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//output: Red Blue Green&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Array Destructuring Assignment Applications
&lt;/h3&gt;

&lt;p&gt;Let's see some practical examples of using the array destructuring assignments syntax.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Swapping variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The array destructuring make it easy to swap values of variables without using a temporary variable:&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;x&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;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;x&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;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 20&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;y&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;ol&gt;
&lt;li&gt;Functions that return multiple values&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In JavaScript, a function can return a value. However, you can return an array that contains multiple values.&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then you use the array destructuring assignment syntax to destructure the elements of the return array into variables:&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="p"&gt;[&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;average&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;state&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;sum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 30&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;average&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So? Did you learned? If you enjoyed and learned something please let me know. See yaa&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tips: Object Destructuring in JavaScript ES6</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Sun, 27 Nov 2022 19:05:04 +0000</pubDate>
      <link>https://forem.com/devvsakib/object-destructuring-in-javascript-es6-13d9</link>
      <guid>https://forem.com/devvsakib/object-destructuring-in-javascript-es6-13d9</guid>
      <description>&lt;p&gt;Suppose you have a &lt;code&gt;person&lt;/code&gt; object with TWO prperties:&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Devv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sakib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before &lt;strong&gt;ES6&lt;/strong&gt;, when you want to assign the variables to the properties of the &lt;code&gt;person&lt;/code&gt; object, you typically do like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But but but, ES6 make it more easier! There are an alternative way to assign properties of an object. Let's see&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;lName&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt; prop are assgined to &lt;code&gt;fName&lt;/code&gt; and &lt;code&gt;lName&lt;/code&gt; variables.&lt;/p&gt;

&lt;p&gt;Syntax:&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="p"&gt;{&lt;/span&gt; 
    &lt;span class="na"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="na"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;variable&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the property name is always on the left whether it is object literal or object &lt;strong&gt;destructuring&lt;/strong&gt; syntax.&lt;/p&gt;

&lt;p&gt;TO KNOW: If the variables have the same name as the properies of the object, you can make the code more concise as follows:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&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;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Sakib"&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;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Smith"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this examples, we declared two variables &lt;code&gt;firstName&lt;/code&gt; and &lt;code&gt;lastName&lt;/code&gt;, and assigned the properties of the object to the variables in the same statement.&lt;/p&gt;

&lt;p&gt;When you assign a property that does not exist to a variable using the object destructuring, the variable is set to &lt;code&gt;undefined&lt;/code&gt;.&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;middleName&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&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;firstName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Sakib"&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;lastName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// "Smith"&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;middleName&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;p&gt;The &lt;code&gt;middleName&lt;/code&gt; property does not exist in the &lt;code&gt;person&lt;/code&gt; object, that's why &lt;code&gt;middleName&lt;/code&gt; is &lt;strong&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Default Values
&lt;/h3&gt;

&lt;p&gt;You are able to assign a default value of the variable when the property of an object doesn't exist.&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Devv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sakib&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="p"&gt;{&lt;/span&gt; 
    &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;middleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&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;middleName&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;In this example, we assigned empty string to the &lt;code&gt;middleName&lt;/code&gt; variable when the &lt;code&gt;person&lt;/code&gt; object doesn't have the &lt;code&gt;middleName&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;However, when the &lt;strong&gt;person&lt;/strong&gt; object has &lt;code&gt;middleName&lt;/code&gt; property, the assignment works as usual:&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 javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Devv&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Sakib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="na"&gt;middleName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;IDK&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="p"&gt;{&lt;/span&gt; 
    &lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;middleName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;person&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;middleName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 'IDK'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Destructuring a null object
&lt;/h3&gt;

&lt;p&gt;If you know, a function may return an object or null in some case.&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;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fname&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;person&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;But you can't destructure an &lt;strong&gt;null&lt;/strong&gt; object. The code will throw a &lt;code&gt;TypeError&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cannot&lt;/span&gt; &lt;span class="nx"&gt;destructure&lt;/span&gt; &lt;span class="nx"&gt;property&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fname&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;person()&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;it&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To solve this, you can use the &lt;code&gt;OR&lt;/code&gt;(||) operator to fallback the &lt;code&gt;null&lt;/code&gt; object t an empty object.&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fname&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;person&lt;/span&gt;&lt;span class="p"&gt;()&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;Now, fname will be &lt;code&gt;undefined&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There are so many destructuring, will write later. See yaa&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>forEach() or map() ? When to use?</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Fri, 30 Sep 2022 05:17:14 +0000</pubDate>
      <link>https://forem.com/devvsakib/foreach-or-map-when-to-use-1a14</link>
      <guid>https://forem.com/devvsakib/foreach-or-map-when-to-use-1a14</guid>
      <description>&lt;p&gt;In this article we'll discuss about &lt;code&gt;forEach&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; method in javascript. Which one best and when to use each one.&lt;/p&gt;

&lt;p&gt;In JavaScript, &lt;code&gt;forEach&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; are two of the most popular methods to work with arrays. Primarily both use to iterate array. So this make a little bit confusion which one we should use.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;forEach&lt;/code&gt; Method:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;forEach&lt;/code&gt; is used to run a function on each element without changing the array. Note, &lt;code&gt;forEach&lt;/code&gt; method doesn’t return anything, if you try to get the return value of the &lt;code&gt;forEach&lt;/code&gt; method, you will get undefined. Since it allows you to modify the source array itself, it’s a mutator method.&lt;/p&gt;

&lt;p&gt;Code 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;// given array&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;//output the square of each number&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;returnVal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; x &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//the array hasn't changed&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="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;returnVal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Output&lt;/span&gt;
&lt;span class="c1"&gt;// 1 x 1 = 1&lt;/span&gt;
&lt;span class="c1"&gt;// 2 x 2 = 4&lt;/span&gt;
&lt;span class="c1"&gt;// 3 x 3 = 9&lt;/span&gt;
&lt;span class="c1"&gt;// 4 x 4 = 16&lt;/span&gt;
&lt;span class="c1"&gt;// 5 x 5 = 25&lt;/span&gt;
&lt;span class="c1"&gt;// [1,2,3,4,5]&lt;/span&gt;
&lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;forEach not returning any new array. The return value of this method is ignored, and the original array doesn't change. The return value of forEach is always undefined.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;map&lt;/code&gt; Method
&lt;/h2&gt;

&lt;p&gt;Similar to forEach method but return NEW ARRAY. It's create new array with return value, but forEach give us undefined. But map doesn't change the given array, so we can say that it’s an immutable method.&lt;/p&gt;

&lt;p&gt;Code 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;// given array&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;//output the square of each number&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;returnVal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//the array hasn't changed&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="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;returnVal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Output&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="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;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, as you see, map method return a new array with the returning value but doesn't change the given array. Given array remains unchanged&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is the differences between forEach and map?
&lt;/h2&gt;

&lt;p&gt;As I said, map returns a new array but forEach return nothing. So, the main difference between map and forEach is that the map method returns a new array by applying the callback function on each element of an array, while the forEach method doesn’t return anything.&lt;br&gt;
&lt;code&gt;forEach&lt;/code&gt; method can be use to mutate the source array. Instead, it's &lt;strong&gt;great&lt;/strong&gt; for when you need to do some action with &lt;strong&gt;each&lt;/strong&gt; element of the array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one to use?
&lt;/h2&gt;

&lt;p&gt;If you’re planning to alter the array elements by applying a function, you should use the map method, since it doesn’t modify the original array and returns a new array. In this way, the original array is kept intact. On the other hand, if you want to loop through all the elements of an array and don’t need a returned array,  use the forEach method.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to star a coding YouTube Channel. Step by Step</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Tue, 27 Sep 2022 18:12:58 +0000</pubDate>
      <link>https://forem.com/devvsakib/how-to-star-a-coding-youtube-channel-step-by-step-5enh</link>
      <guid>https://forem.com/devvsakib/how-to-star-a-coding-youtube-channel-step-by-step-5enh</guid>
      <description>&lt;p&gt;Most of us want to start a YouTube channel. But they don't know where to start. To i will walk you through the process from absolute beginners.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First:&lt;/strong&gt;&lt;br&gt;
Before creating YouTube channel, we need some tool. For voice recording you need an good quality microphone or you can use your headphone mic or use your Mobile for voice recording. Then you need screen recorder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Channel Name Selection
&lt;/h2&gt;

&lt;p&gt;I always recommend using your name as your youtube channel name. It's help you to find you all over the network. Using your name as a channel name can help to better associate you with your content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create YouTube Logo and Brand Icon
&lt;/h2&gt;

&lt;p&gt;After selecting your YouTube channel name, you need to create your channel Logo and Brand icon you see use in video as video watermark, when you click, it's say SUBSCRIBEEEE. Don't forget to create COVER too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create YouTube channel as Brand Channel
&lt;/h2&gt;

&lt;p&gt;Create the account for your YouTube channel and create your channel as a Brand Account. This allows you to keep some separation between your personal Google account and your software YouTube channel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Your Goals For your YouTube Channel
&lt;/h2&gt;

&lt;p&gt;First you need to decide what is your goal for your channel.&lt;br&gt;
For example, helping other, give you some reason to learn, why people will watch your video, making money through YouTube ad revenue, sponsorships, and affiliate links&lt;/p&gt;

&lt;p&gt;When thinking about your channel and the videos you want to make, don’t worry if you want to create a video about a topic that someone else has already done. There are a lot of potential viewers in the world, and there are probably some people that can learn best from your unique style.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Intro
&lt;/h2&gt;

&lt;p&gt;I hope you know what i mean bu Your Intro. Basically, every youtuber has their own intro. An intro is exactly what it sounds like, a introductory video that tells the viewer everything they need to know about your product/service and business while also setting the tone for your brand and the rest of your content. Do not jump for " Hello everyone welcome to my youtube channel" bla bla... Instead of this, you can say "Hey I'm Your Host X". So, create your intro right now...&lt;/p&gt;

&lt;h2&gt;
  
  
  Content type for your YouTube Channel
&lt;/h2&gt;

&lt;p&gt;The most important of this article and your youtube channel is what type of tutorial video you are making. Content type mean, there are ton of content type like gaming, funny, music video etc. So you want to create a coding youtube channel, then you have to make your content only coding related. It doesn't mean you are uploading gaming video and coding video on your channel, that's make sense right. Do not break your rule, stick with it. Keep uploading video. Never stop&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Only Loser stop after start&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example channels:&lt;br&gt;
&lt;a href="https://www.youtube.com/c/CodeWithHarry" rel="noopener noreferrer"&gt;CodeWithHarry&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/c/WebDevSimplified" rel="noopener noreferrer"&gt;WebDevSimplified&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/c/Freecodecamp" rel="noopener noreferrer"&gt;Freecodecamp&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  YouTube video Scripting
&lt;/h2&gt;

&lt;p&gt;Do not start recording without script. Write a script, no need to write whole script. Just write some major point of your video you must need. And describe them very clearly. Most of people do the same mistake, they start recording and stuck in video while talking and that's make so unprofessional. Write script, use your secondary screen or mobile or write on paper, You will see an outstanding output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Screen Recording Tips
&lt;/h2&gt;

&lt;p&gt;If you are showing code on screen, make it as large as possible. Why? So basically, when we watch tutorial on YouTube when we see small font size, most of people watch tutorial on MOBILE so it's make sense to use large font right? It's an important issue to keep in your mind while writing code you  need to make it as large as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Video edit
&lt;/h2&gt;

&lt;p&gt;You don't need high level video editing software to edit your video. I will suggest you to use Filmora, Camtasia or if you are familiar with Adobe Premiere Pro. And i definitely don't suggest Premiere pro for beginners. Make sure your AUDIO and Video are exactly matched if you recorded your audio video with different software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose a Title for your YouTube video
&lt;/h2&gt;

&lt;p&gt;For most types of videos, it's best to pick a title that people are searching for. There are two main ways to find what people are searching for: YouTube search autocomplete and Google Trends. Take a look at YouTube Search. Type your main keyword and see what's next word showing. Make sure you are using Private window or Incognito Mode&lt;/p&gt;

&lt;p&gt;For example: &lt;br&gt;
type "javascript"&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%2Fdpo5zgeeobxhktuor3mm.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%2Fdpo5zgeeobxhktuor3mm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Video THUMBNAIL
&lt;/h1&gt;

&lt;p&gt;The most important,  A great custom video thumbnail can make all the difference when it comes to a viewer clicking through to your video. A good thumbnail makes you want to watch the video. A bad thumbnail or no thumbnail does not make a good impression. SO take your enough time to make thumbnaillllllllllllllll. After finishing thumbnail, ask your self will click my video if i use this thumbnail? If yes, Then you are good to go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Uplaod your video in time
&lt;/h2&gt;

&lt;p&gt;Always try to upload your video in same time.&lt;/p&gt;

&lt;p&gt;I just wanted to give you a simple beginners guide to start your &lt;strong&gt;Coding YouTube Channel&lt;/strong&gt; . I hope this article will help you to start your channel. Do not quite, Stay Stay Stay. Give your best, you will definitely see the result&lt;/p&gt;

&lt;p&gt;For more, visit &lt;a href="http://devvsakib.me/blog" rel="noopener noreferrer"&gt;DevvSakib&lt;/a&gt;&lt;/p&gt;

</description>
      <category>youtube</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>community</category>
    </item>
    <item>
      <title>Fetch API in JavaScript</title>
      <dc:creator>Sakib Ahmed</dc:creator>
      <pubDate>Sun, 25 Sep 2022 10:41:08 +0000</pubDate>
      <link>https://forem.com/devvsakib/fetch-api-in-javascript-54o6</link>
      <guid>https://forem.com/devvsakib/fetch-api-in-javascript-54o6</guid>
      <description>&lt;p&gt;Basic Fetch request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how to fetch in javascript. Very simple!&lt;/p&gt;

&lt;p&gt;Wait not done yet.&lt;/p&gt;

&lt;p&gt;The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses. Before fetch(), we used XHR (XMLHttpRequest). Using Fetch is very easy. Fetch() starts the process of fetching a resource from a server and returns Promise that resolves to a Response object.&lt;br&gt;
So we dont need XMLHttpRequest anymore. But yeah, we need xhr for ajax.&lt;/p&gt;

&lt;p&gt;But how XMLHttpRequest is look like? how to write ? &lt;br&gt;
Lets see:&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;// Create an XMLHttpRequest object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;xhttp&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;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Define a callback function&lt;/span&gt;
&lt;span class="nx"&gt;xhttp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Here you can use the Data&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Send a request&lt;/span&gt;
&lt;span class="nx"&gt;xhttp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GET&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ajax_info.txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;xhttp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  fetch()
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://example.com/movies.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are fetching a JSON file from our desire server and printing it to the console. The simplest use of fetch() takes one argument — the path to the resource you want to fetch — and does not directly return the JSON response body but instead returns a promise that resolves with a Response object.&lt;/p&gt;

&lt;p&gt;The Response object, in turn, does not directly contain the actual JSON response body but is instead a representation of the entire HTTP response. So, to extract the JSON body content from the Response object, we use the json() method, which returns a second promise that resolves with the result of parsing the response body text as JSON.&lt;/p&gt;

&lt;h3&gt;
  
  
  Real Example:
&lt;/h3&gt;

&lt;p&gt;Fetch url: &lt;a href="https://my-json-server.typicode.com/typicode/demo/posts" rel="noopener noreferrer"&gt;https://my-json-server.typicode.com/typicode/demo/posts&lt;/a&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="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://my-json-server.typicode.com/typicode/demo/posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// output: 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go to the link. We are fetching json from this url.&lt;/p&gt;

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

&lt;p&gt;for more example, check my codepen code &lt;a href="https://codepen.io/devvsakib/pen/JjJqQoR" rel="noopener noreferrer"&gt;FETCH "BRAKING BAD" CHARACTER&lt;/a&gt;&lt;/p&gt;

</description>
      <category>api</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
