<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Runo-saduwa</title>
    <description>The latest articles on DEV Community by Runo-saduwa (@runosaduwa).</description>
    <link>https://dev.to/runosaduwa</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%2F96248%2F1269c1bd-0c4f-471e-bb61-eb0db16409ab.jpg</url>
      <title>DEV Community: Runo-saduwa</title>
      <link>https://dev.to/runosaduwa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/runosaduwa"/>
    <language>en</language>
    <item>
      <title>2020: Year in review</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Thu, 31 Dec 2020 11:00:09 +0000</pubDate>
      <link>https://dev.to/runosaduwa/2020-year-in-review-3h58</link>
      <guid>https://dev.to/runosaduwa/2020-year-in-review-3h58</guid>
      <description>&lt;h3&gt;
  
  
  School
&lt;/h3&gt;

&lt;p&gt;I'm a final year student of the Federal University of Petroleum Resources, Delta State (FUPRE) and over 70% of FUPRE's lecturers are under the &lt;strong&gt;Academic Staff Union of Universities (ASUU)&lt;/strong&gt; which embarked on a nationwide strike that lasted for 8 months. This means that Nigerian students in higher-institutions affected by this strike have been out of school for 8 months. &lt;/p&gt;

&lt;p&gt;This was bad news for a lot of students especially the final year students like myself but... &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For Everything you have missed you have gained something else. - Ralph Waldo Emerson&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I want to use this opportunity to thank the ASUU Chairman, Prof. Biodun Ogunyemi for giving me a break from school. This strike was the beginning of new things for me, I had enough time to grow exponentially in my software engineering career and also make a lot of money before I turned 21. &lt;/p&gt;

&lt;h3&gt;
  
  
  Career
&lt;/h3&gt;

&lt;p&gt;So like I said earlier, I grew exponentially in my software engineering career. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I made significant contributions to open-source by contributing to the &lt;a href="https://joplinapp.org/"&gt;Joplin Project&lt;/a&gt;. I'm really proud of this because anyone who knows about Open-source knows how difficult it is to make a pull request but with no prior experience I was able to get over 4 of my pull requests merged.&lt;/li&gt;
&lt;li&gt;I helped in launching a brilliant fintech product. I got a contract from a startup based in the United states to help them build their product. This startup has been battling with finding the right talent to properly build their User Interface. Prior to our contract, they had worked with 4 different teams that couldn't deliver the product successfully but when I came onboard I was able to ship the product to production in less than 6 months.&lt;/li&gt;
&lt;li&gt;I was able to work with someone i hold in high-esteem. A very talented Senior Software engineer and my experience working with him improved my technical skills by 100%!&lt;/li&gt;
&lt;li&gt;I secured a 3 months internship with a company in San Francisco.&lt;/li&gt;
&lt;li&gt;I got a full-time job, now I got a stable income from writing code!&lt;/li&gt;
&lt;li&gt;I worked with a lot of interesting technologies such as React, React Native, Cloud services (AWS), GraphQL, Figma and also became more conscious about building high-performance, maintainable, scalable, accessible and modern web and mobile applications. As a bad guy ;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Money
&lt;/h3&gt;

&lt;p&gt;Close friends know that I love money (I mean, who doesn't?) and this year I made a lot of it and all I can say is Money is good.&lt;/p&gt;

&lt;p&gt;My self-esteem has broken the charts, I feel 10x more confident than I was in 2019, my net-worth increased by over 100%. I'm a much more happier person and even when i'm down or sad its never because of lack of money because these days I spend to cure any pain i'm experiencing. I can now afford things I desire to have without (too much) tears, this year i changed all my gadgets to some of the best out there and i hope to do this again next year, I'm now a blessing to myself, family and anyone that comes to my presence. &lt;/p&gt;

&lt;h3&gt;
  
  
  Investments
&lt;/h3&gt;

&lt;p&gt;Earlier this year, sometime in the month of May when i saw that i had over half a million in my possession i decided to try crypto trading so I enrolled in a crypto trading school, bought some satoshi and decided to trade in my spare time but unfortunately i couldn't cope with the trading school because I got very busy with my contract job.&lt;/p&gt;

&lt;p&gt;After my crypto trading experience i decided not to go into such a venture till i'm very sure about my time schedule.&lt;/p&gt;

&lt;p&gt;Presently i enrolled in a 2 months Product Design course.&lt;/p&gt;

&lt;p&gt;I was also awarded with some shares from the company i work for in San Franciso, documents signed and sealed!&lt;/p&gt;

&lt;h3&gt;
  
  
  Relationships
&lt;/h3&gt;

&lt;p&gt;I've been far away from my friends and it's been painful but i guess that's the price i had to pay for jumping into the adult lifestyle so early because most of my friends can't relate to things i'm experiencing in life right now so it's hard to maintain a long conversation with most of them.&lt;/p&gt;

&lt;p&gt;I made a lot of friends at work though, really awesome people!&lt;/p&gt;

&lt;p&gt;Girlfriend?, omo. Still haven't found who's worth my time, love, money and full commitment because i'm a spec and a spec needs a spec but specs are hard to find so we keep searching (no settling down for low quality).&lt;/p&gt;

&lt;p&gt;Family?, I built a solid relationship with my parents and siblings. I hide nothing from my parents, they know how much i earn, my situationships, my scuffles and everything else.&lt;/p&gt;

&lt;h3&gt;
  
  
  COVID19
&lt;/h3&gt;

&lt;p&gt;Myself, my family, friends, colleagues, and everyone around me didn't contract it. Thank God!&lt;/p&gt;

&lt;h3&gt;
  
  
  Talks and Tecnical writing
&lt;/h3&gt;

&lt;p&gt;This year i wasn't too active in the community, i wrote only one technical article and gave one talk which was at the Facebook Build Day. Next year will be much better!&lt;/p&gt;

&lt;h3&gt;
  
  
  Wins
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I contributed to open source&lt;/li&gt;
&lt;li&gt;I got my first dollar paying contract&lt;/li&gt;
&lt;li&gt;I got an Internship with a startup based in San Francisco&lt;/li&gt;
&lt;li&gt;I helped ship a brilliant fintech product (It's the next big thing, watch out!)&lt;/li&gt;
&lt;li&gt;New Gadgets, i changed all&lt;/li&gt;
&lt;li&gt;I got a full time job&lt;/li&gt;
&lt;li&gt;I gave a lot in 2020 and i felt great doing it. I pray for more blessing to be a blessing to people.&lt;/li&gt;
&lt;li&gt;Net-worth increased by 100%&lt;/li&gt;
&lt;li&gt;I supported my family morally and financially&lt;/li&gt;
&lt;li&gt;I turned 21 and i didn't die this year&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Notable Losses
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;I lost my grandma (80 years)&lt;/li&gt;
&lt;li&gt;I couldn't participate in GSoC (Google student Internship)&lt;/li&gt;
&lt;li&gt;I didn't learn crypto trading after paying $200 for the training, it was all my fault.&lt;/li&gt;
&lt;li&gt;My application to Microsoft was rejected. no reasons given&lt;/li&gt;
&lt;li&gt;My application to Goldman Sachs was rejected. no reasons given.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Gratitude
&lt;/h3&gt;

&lt;p&gt;I'm full of thanks. 2020 has been awesome, My wins overshadowed my losses. I'm looking forward to what 2021 has in store for me, the possibilities are endless, its gonna be a really big year, more growth, more money and more records to be broken. Right now my only goal for 2021 is to do 10x better than I did in 2020.&lt;/p&gt;

&lt;p&gt;Thanks for reading, please like and share!, Happy new year in Advance!!&lt;/p&gt;

</description>
      <category>lifestyle</category>
      <category>grow</category>
      <category>developer</category>
    </item>
    <item>
      <title>Go variables: the bare minimum knowledge</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 25 Jan 2020 17:03:03 +0000</pubDate>
      <link>https://dev.to/runosaduwa/go-variables-the-bare-minimum-knowledge-3l6o</link>
      <guid>https://dev.to/runosaduwa/go-variables-the-bare-minimum-knowledge-3l6o</guid>
      <description>&lt;p&gt;Variables are one of the most important features of any programming language. It helps us to store data and also distribute data to various parts of our applications. &lt;/p&gt;

&lt;p&gt;Here and now, we’ll learn what’s really necessary to learn about variables in Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  First things first, The &lt;code&gt;var&lt;/code&gt; keyword
&lt;/h2&gt;

&lt;p&gt;Variables are declared in Go with the &lt;br&gt;
&lt;code&gt;var&lt;/code&gt; keyword. Easy peasy, let’s move on.&lt;/p&gt;
&lt;h1&gt;
  
  
  How to declare a variable
&lt;/h1&gt;

&lt;p&gt;Let’s say we want to declare a variable called &lt;code&gt;language&lt;/code&gt; which will hold a string value, how do we do that in Go?&lt;/p&gt;

&lt;p&gt;Easy, we’ll simply write the &lt;code&gt;var&lt;/code&gt; keyword followed by the variable name, which is &lt;code&gt;language&lt;/code&gt; and finally the type of our variable, in this case it’s a &lt;code&gt;string&lt;/code&gt;. See the code snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go is a typed language so you should &lt;em&gt;&lt;strong&gt;never omit specifying the type of the variable if it hasn’t yet been initialized with a value&lt;/strong&gt;&lt;/em&gt;. We’ll talk about variable initialization in the next section.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to initialize a variable
&lt;/h1&gt;

&lt;p&gt;By now, we all know variables are like containers where we keep things, so what is &lt;em&gt;&lt;strong&gt;variable initialization&lt;/strong&gt;&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;variable initialization&lt;/strong&gt;&lt;/em&gt; is simply the process of assigning a value to a variable. So, in other words it’s like the process of putting things into a container.&lt;/p&gt;

&lt;p&gt;Great, so how do we intialize a variable with a value in Go? &lt;/p&gt;

&lt;p&gt;Looking back at our previous example above, let’s say we want to assign a value to the &lt;code&gt;language&lt;/code&gt; variable. This can be accomplished by using the&lt;br&gt;
 &lt;code&gt;=&lt;/code&gt; operator, see the example below!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;English&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//English &lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When a variable is declared and &lt;em&gt;&lt;strong&gt;explicitly&lt;/strong&gt;&lt;/em&gt; initialized with a value, you can avoid specifying the type of the variable. The variable will take the type of the initializer, this is called &lt;strong&gt;&lt;em&gt;inferred typing&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;English&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//English&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Implicit initialization
&lt;/h1&gt;

&lt;p&gt;When a variable is declared without being initialized with a variable, it is implicitly initialized with a value according to the type of the variable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If its a &lt;code&gt;string&lt;/code&gt; type, it is initialized with &lt;code&gt;’’&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;if it’s an interger &lt;code&gt;int&lt;/code&gt; type, it’s initialized with &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;if it’s a Boolean type it’s initialized with &lt;code&gt;false&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;married&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;married&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//‘’, 0, false&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  The short assignment statement
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Inside a function&lt;/em&gt; you can initialize a variable with the &lt;strong&gt;short assignment statement&lt;/strong&gt; &lt;code&gt;:=&lt;/code&gt; to save yourself time and to keep your code elegant and readable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="n"&gt;Runo&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//name&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;REMINDER&lt;/strong&gt;: this can only be done inside a function and not in the package level.&lt;/p&gt;

&lt;p&gt;Well, there you have it!, in my opinion this is the bare minimum knowledge one needs to work comfortably with Go variables.&lt;/p&gt;

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

</description>
      <category>go</category>
      <category>softwareengineering</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Install React Native with Expo - Quick &amp; Easy</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 25 Jan 2020 16:43:35 +0000</pubDate>
      <link>https://dev.to/runosaduwa/how-to-install-react-native-with-expo-quick-easy-4j8j</link>
      <guid>https://dev.to/runosaduwa/how-to-install-react-native-with-expo-quick-easy-4j8j</guid>
      <description>&lt;p&gt;Hey there!, so you want to get into mobile development or you're already familier with mobile development and you want to install/set-up React Native on your machine, but your machine is slow😥 and or you live in a country where the cost of good internet data is quite expensive so you can’t afford to install Android studio or Xcode&lt;/p&gt;

&lt;p&gt;Never say never!, after reading this you'll have React Native up and running on your machine without consuming ridiculous amount of space on your machine with the help of this life saver called Expo!, Lets get started.&lt;/p&gt;

&lt;h4&gt;
  
  
  STEP 1 - Install Node.js
&lt;/h4&gt;

&lt;p&gt;If you have the Node 10 LTS or greater installed on your machine. kindly move to the next step!, If you dont, visit &lt;a href="https://nodejs.org/en/"&gt;nodejs website&lt;/a&gt; to install the recommended version for your OS.&lt;/p&gt;

&lt;h4&gt;
  
  
  STEP 2 - Install the Expo CLI
&lt;/h4&gt;

&lt;p&gt;We'll install Expo CLI with npm, npm comes along with Node, you can confirm this by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;it will print the version of npm installed in your machine.&lt;/p&gt;

&lt;p&gt;Now, we install Expo CLI by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; expo-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  STEP 3 - Create a new React Native project
&lt;/h4&gt;

&lt;p&gt;Run the following commands to create a new React Native project called "NewProject":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;expo init NewProject

&lt;span class="nb"&gt;cd &lt;/span&gt;NewProject
npm start &lt;span class="c"&gt;# you can also use: expo start&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Awesome!!, now you've successfully installed and set-up a new project, next step you'll learn how to run your app.&lt;/p&gt;

&lt;h4&gt;
  
  
  STEP 4 - Running your React Native application
&lt;/h4&gt;

&lt;p&gt;Install the Expo client app on your iOS or Android phone and connect to the same wireless network as your computer. On Android, use the Expo app to scan the QR code from your terminal to open your project. On iOS, follow on-screen instructions to get a link.&lt;/p&gt;

&lt;p&gt;Congratulations!!, You have successfully installed React Native, go forth and build!!!❤️❤️❤️&lt;/p&gt;

</description>
      <category>mobile</category>
      <category>reactnative</category>
      <category>react</category>
      <category>expo</category>
    </item>
    <item>
      <title>The var keyword</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 15 Dec 2018 18:04:13 +0000</pubDate>
      <link>https://dev.to/runosaduwa/the-var-keyword-5gpm</link>
      <guid>https://dev.to/runosaduwa/the-var-keyword-5gpm</guid>
      <description>&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj29y0qb9yuq0koky66zs.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fj29y0qb9yuq0koky66zs.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before ES6, all variables in JavaScript were declared with the var keyword. This keyword causes our variables to have a function scope.&lt;/p&gt;

&lt;p&gt;Lets understand this better with the following code snippet:&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;SayName&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&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 console prints out &lt;code&gt;undefined&lt;/code&gt; because the variable &lt;code&gt;name&lt;/code&gt; inside the &lt;code&gt;SayName&lt;/code&gt; function is &lt;strong&gt;not&lt;/strong&gt; visible outside the &lt;code&gt;SayName&lt;/code&gt;function.&lt;/p&gt;

&lt;p&gt;The behaviour is quite different in another block that is not a function block. For example, see what happens in an if block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="k"&gt;if&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;//Tega&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The console prints &lt;code&gt;Tega&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Considering the results from the two examples, it is evident that variables declared with the &lt;code&gt;var&lt;/code&gt; keyword have a local scope &lt;strong&gt;only&lt;/strong&gt; when they are found within a function block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's a bad behaviour&lt;/strong&gt;&lt;br&gt;
This is a bad behaviour that has caused a lot of frustration amongst JavaScript programmers. Prior to ES6, JavaScript had function scope, but &lt;em&gt;block scoping&lt;/em&gt; is more common in most programming languages. With ES6, &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords were introduced to allow us to declare variables that are block scoped which is a safe behaviour.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;br&gt;
Happy Coding!❤&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>let, const &amp; Block scoping</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 15 Dec 2018 18:03:01 +0000</pubDate>
      <link>https://dev.to/runosaduwa/let-const--block-scoping-5ca4</link>
      <guid>https://dev.to/runosaduwa/let-const--block-scoping-5ca4</guid>
      <description>&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy9zb6hktm7ndk6oi920x.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy9zb6hktm7ndk6oi920x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;What is block scoping?!&lt;/h1&gt;

&lt;p&gt;Quite simply, this means a new scope is created between a pair of &lt;code&gt;{}&lt;/code&gt;. Unlike the &lt;code&gt;var keyword&lt;/code&gt;, the variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; can only exist within the innermost block that surrounds them.&lt;/p&gt;

&lt;p&gt;In the following example, what do you think will be printed to the console when the code is executed.&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value &lt;code&gt;Runo&lt;/code&gt; is printed to the console because the second variable &lt;code&gt;name&lt;/code&gt; is not visible outside the block, it simply doesn't exist outside the block.&lt;/p&gt;

&lt;h2&gt;let &amp;amp; const: Similarities&lt;/h2&gt;

&lt;p&gt;In this section, we'll look at the similarities between the &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords in different use cases:&lt;/p&gt;

&lt;h3&gt;
  
  
  Block Scoping
&lt;/h3&gt;

&lt;p&gt;We know that the &lt;code&gt;var keyword&lt;/code&gt; is bound to &lt;code&gt;function scope&lt;/code&gt;, whereas &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are&lt;br&gt;
&lt;code&gt;block scoped&lt;/code&gt; which means that if you have a set of curly braces &lt;code&gt;{}&lt;/code&gt; you have a &lt;code&gt;block scope&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  One declaration per scope
&lt;/h3&gt;

&lt;p&gt;This means that &lt;code&gt;let&lt;/code&gt; and  &lt;code&gt;const&lt;/code&gt; can be used to declare a particular variable only once within its scope, lets see an example to level our understanding:&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same goes for &lt;code&gt;const&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the &lt;code&gt;var keyword&lt;/code&gt; acts differently, it allows a variable to be declared twice and then it takes the value of the most recent declaration, see the code snippet below:&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Tega&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;Let &amp;amp; const: Differences&lt;/h2&gt;

&lt;p&gt;In this section we'll look at the differences between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; and when to use them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Variable initialization
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const&lt;/code&gt; variables &lt;strong&gt;must&lt;/strong&gt; be initialized with a value, but  &lt;code&gt;let&lt;/code&gt; variables don't always require an intialization 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;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//Syntax error&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variable reassignment
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; variables can be reassigned to another value, whereas &lt;code&gt;const&lt;/code&gt; variables cannot. See the following:&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tega&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Tega&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;const&lt;/code&gt; variables &lt;strong&gt;cannot&lt;/strong&gt; be reassigned, see below:&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;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.142&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;pi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//uncaught typeError &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;const&lt;/code&gt; should be used to hold variables whose values remain constant throughout the program. It can be used to create variables that hold references to the DOM. &lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;const and let&lt;/code&gt; keywords support block scoping (lexical binding) and the &lt;code&gt;const&lt;/code&gt; key word is used to declare variables with constant values, whereas the &lt;code&gt;let&lt;/code&gt; keyword is used to declare variables whose values can change in the course of programming. The &lt;code&gt;let&lt;/code&gt; keyword is a good replacement for legacy ES5 &lt;code&gt;var&lt;/code&gt; keyword. &lt;/p&gt;

</description>
      <category>es6</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Default Function Parameters (ES6)</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 15 Dec 2018 18:02:05 +0000</pubDate>
      <link>https://dev.to/runosaduwa/default-functions-es6-gbo</link>
      <guid>https://dev.to/runosaduwa/default-functions-es6-gbo</guid>
      <description>&lt;p&gt;In the ES5 days, to set default values you might write your code in this manner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;a&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//42&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//42&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;These are good solutions, but hey it's 2019, Modern JavaScript is here to rescue us from this long walk. Now, you can set default values to the parameters in the function declaration statement itself like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;//42&lt;/span&gt;
 &lt;span class="nx"&gt;getSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you don't specify an argument, the default value of the parameters gets used. &lt;/p&gt;

&lt;p&gt;Compared to the older methods of setting default values, this new feature provided by ES6 is easier and much cleaner.&lt;/p&gt;

&lt;p&gt;Happy Coding!❤&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>es6</category>
      <category>javascript</category>
    </item>
    <item>
      <title>ES6 Rest and Spread Operators</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 15 Dec 2018 17:57:30 +0000</pubDate>
      <link>https://dev.to/runosaduwa/es6-rest-and-spread-operators-dep</link>
      <guid>https://dev.to/runosaduwa/es6-rest-and-spread-operators-dep</guid>
      <description>&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwwnx9xpy59s885qq1a72.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwwnx9xpy59s885qq1a72.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ES6 added a lot of cool features to JavaScript. The &lt;code&gt;Rest&lt;/code&gt; and &lt;code&gt;Spread&lt;/code&gt; operators are powerful new features that allow us to access and manipulate data easily.&lt;/p&gt;

&lt;p&gt;The word &lt;code&gt;Rest&lt;/code&gt; here simply means &lt;em&gt;gathering up parameters and putting them all into a &lt;strong&gt;single array&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Also, the word &lt;code&gt;Spread&lt;/code&gt; refers to &lt;em&gt;&lt;strong&gt;spreading&lt;/strong&gt; out the elements of an iterable (arrays, objects and strings).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;They both make use of the &lt;em&gt;three dots&lt;/em&gt; &lt;code&gt;...&lt;/code&gt; but apply it differently to suit their purpose. &lt;/p&gt;

&lt;p&gt;In this post, we'll learn about the &lt;code&gt;Rest&lt;/code&gt; and &lt;code&gt;Spread&lt;/code&gt;  operators, how to use them and when to use them.&lt;/p&gt;

&lt;h3&gt;Table of Content:&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Rest Operators&lt;/li&gt;
&lt;li&gt;Spread Operators&lt;/li&gt;
&lt;li&gt;Summary&lt;/li&gt;

&lt;/ul&gt;

&lt;h1&gt;
  
  
  Rest Operators
&lt;/h1&gt;

&lt;p&gt;As we stated earlier, The &lt;code&gt;Rest&lt;/code&gt; operators gather up parameters and put them all in a single array.&lt;/p&gt;

&lt;p&gt;It makes use of the &lt;code&gt;...&lt;/code&gt; symbol which precedes a named parameter that will become an array that will just gather up the &lt;em&gt;remaining&lt;/em&gt; parameters passed to a function. See the following 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;showNames&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;names&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;names&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="nf"&gt;showNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&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;Tega&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;Ejiro&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ["Runo","Tega","Ejiro"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the &lt;code&gt;rest parameter&lt;/code&gt; is &lt;code&gt;names&lt;/code&gt; which is preceded by a &lt;code&gt;...&lt;/code&gt; to denote that &lt;code&gt;names&lt;/code&gt; is indeed a &lt;code&gt;rest parameter&lt;/code&gt;. When the function is invoked the console prints the value of &lt;code&gt;names&lt;/code&gt; as &lt;code&gt;["Runo","Tega","Ejiro"]&lt;/code&gt; which is an array created by &lt;em&gt;gathering&lt;/em&gt; all the arguments passed into the, into the &lt;code&gt;showNames&lt;/code&gt; functions. &lt;/p&gt;

&lt;h4&gt;
  
  
  When You Should Use the &lt;em&gt;Rest Operators &lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;rest operators&lt;/code&gt; can be very useful when you need to create function definitons that can accept unlimited number of parameters, let's see an 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;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="nf"&gt;add&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;//3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first function call, &lt;code&gt;add(1,2)&lt;/code&gt; returns 3. This is quite normal and straight forward, but what if you needed to pass in more arguments to your function to help you add more than 2 parameters?&lt;/p&gt;

&lt;p&gt;After invoking the next &lt;code&gt;add&lt;/code&gt; function which is &lt;code&gt;add(1, 2, 3, 4, 5)&lt;/code&gt; we'll still get &lt;code&gt;3&lt;/code&gt; because in JavaScript you can call a function with any number of arguments but the number of arguments that will be used depends on the number of parameters specified in the function definition.&lt;/p&gt;

&lt;p&gt;In this case, only 2 parameters are specified. Hence, Javascript picks up the first 2 arguments.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rest parameters to the rescue
&lt;/h4&gt;

&lt;p&gt;With the &lt;code&gt;rest parameters&lt;/code&gt; we can gather any number of arguments into an array and do whatever you want with them. We can use array methods like higher-order functions like &lt;code&gt;forEach(), map(), reduce()&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Using rest parameters, we can rewrite the add function 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;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;rest&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;total&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="k"&gt;return&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;total&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//3&lt;/span&gt;
&lt;span class="nf"&gt;add&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="c1"&gt;//6&lt;/span&gt;
&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//21&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;By doing so, we have succeeded in making our function flexible and adaptable to accept as much arguments as possible because the rest parameter will gather them up in an array and we make good use of the &lt;code&gt;forEach()&lt;/code&gt; method to iterate over each element in the array add it to the &lt;code&gt;total&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you need to specify a parameter (or parameters) alongside a &lt;code&gt;rest parameter&lt;/code&gt;, ensure that the rest parameter is &lt;strong&gt;last&lt;/strong&gt; in your function definition.&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;allNames&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="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="nx"&gt;name3&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;name2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Error!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;allNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&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;Tega&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;Ejiro&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;Simi&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;Gare&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;Please DON'T DO this, it doesn't make any sense to JavaScript. The &lt;code&gt;rest parameters&lt;/code&gt; job is to gather the excess arguments that will be passed into a function. This function should be rewritten like so:&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;allNames&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;name3&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;name2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Tega&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;name3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ["Ejiro", "Simi", "Gare"];&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;name3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 3&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;allNames&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&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;Tega&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;Ejiro&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;Simi&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;Gare&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;It's also important to know that the &lt;code&gt;length property&lt;/code&gt; of functions ignores the &lt;code&gt;rest parameters&lt;/code&gt;, lets see what we'll get if we try to find the length of the &lt;code&gt;allNames&lt;/code&gt; function:&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;allNames&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;name3&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;name2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Tega&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;allNames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Spread Operators
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;spread operator&lt;/code&gt; simply does the opposite of what the rest operator does, it &lt;em&gt;unpacks&lt;/em&gt; an array.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;spread operator&lt;/code&gt; can be used with other iterable data types like strings and objects.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;spread operator&lt;/code&gt; is applied in the following scenarios:&lt;/p&gt;

&lt;h3&gt;
  
  
  When you need to copy an array
&lt;/h3&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;arr&lt;/span&gt; &lt;span class="o"&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;a&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;b&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;c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newArr&lt;/span&gt; &lt;span class="o"&gt;=&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;newArr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ["a", "b", "c"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its that's easy, all you need to do is to add a preceding  &lt;code&gt;...&lt;/code&gt; to an existing array and it simply removes all the values from the array.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding array elements to another array
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&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;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newArr&lt;/span&gt; &lt;span class="o"&gt;=&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;c&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;d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newArr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//["a", "b", "c", "d"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The values of &lt;code&gt;arr&lt;/code&gt; is transferred to &lt;code&gt;newArr&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Splitting Strings
&lt;/h3&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 'R' 'u' 'n' 'o'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Merge Objects
&lt;/h3&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;obj1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;19&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj2&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;obj3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// {name: "Runo", age: 19}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;rest operator&lt;/code&gt;stores the remaining data passed into a function in an array. In other words, it creates a new array. On the other hand, The &lt;code&gt;spread operator&lt;/code&gt; simply works with an &lt;strong&gt;existing&lt;/strong&gt; array or iterable like strings and objects, It's commonly used in modern frameworks like &lt;code&gt;ReactJs&lt;/code&gt;to copy data from &lt;code&gt;state&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;I hope this helps someone, Happy Coding fam!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>es6</category>
      <category>intermediate</category>
    </item>
    <item>
      <title>JavaScript's friendliest for loop: for...of loop </title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Sat, 15 Dec 2018 17:53:23 +0000</pubDate>
      <link>https://dev.to/runosaduwa/javascripts-friendliest-for-loop-forof-loop--1gan</link>
      <guid>https://dev.to/runosaduwa/javascripts-friendliest-for-loop-forof-loop--1gan</guid>
      <description>&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flspnw6e19x5hg2n8qt7v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flspnw6e19x5hg2n8qt7v.jpg"&gt;&lt;/a&gt;&lt;br&gt;
For many years in JavaScript, we have been &lt;strong&gt;iterating&lt;/strong&gt; over &lt;strong&gt;iterables&lt;/strong&gt; using the &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;for-in&lt;/code&gt; and &lt;code&gt;forEach&lt;/code&gt;(in the case of arrays).&lt;/p&gt;

&lt;p&gt;I can't imagine how hard programming will be without these structures, they have indeed saved lives but ES6 is here again, with yet another powerful, cleaner and in my opinion, the most friendliest for loop: the &lt;code&gt;for...of&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;for...of&lt;/code&gt; loop allows iteration over iterable objects such as arrays, strings, maps, etc with lesser and cleaner syntax.&lt;/p&gt;

&lt;p&gt;Let's consider a regular &lt;code&gt;for-loop&lt;/code&gt; for iterating over an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&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;runo&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;peter&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;saduwa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
 &lt;span class="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;names&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// runo&lt;/span&gt;
&lt;span class="c1"&gt;// peter&lt;/span&gt;
&lt;span class="c1"&gt;// saduwa&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;There's absolutely nothing wrong with this style, But with the &lt;code&gt;for...of&lt;/code&gt; syntax we can achieve the same thing without having to initialize a counter variable &lt;code&gt;i&lt;/code&gt; to keep track of the loop. See how we can use the &lt;code&gt;for...of&lt;/code&gt; syntax to make our code much cleaner and readable:&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;names&lt;/span&gt; &lt;span class="o"&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;runo&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;peter&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;saduwa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;names&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;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// runo&lt;/span&gt;
&lt;span class="c1"&gt;// peter&lt;/span&gt;
&lt;span class="c1"&gt;// saduwa&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;See how clean the code looks, the &lt;code&gt;name&lt;/code&gt; variable represents each element in the &lt;code&gt;names&lt;/code&gt; array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the value you loop over using the &lt;code&gt;for...of&lt;/code&gt; loop must be an iterable. An iterable is simply an object that is able to produce an iterator. Examples of iterables in JavaScript are the arrays, strings, maps and sets, etc. Also node lists from the Dom tree.&lt;/p&gt;

&lt;p&gt;Simple iteration over a string:&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;letter&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;name&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;letter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// R&lt;/span&gt;
&lt;span class="c1"&gt;// u&lt;/span&gt;
&lt;span class="c1"&gt;// n&lt;/span&gt;
&lt;span class="c1"&gt;// o&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;for...of&lt;/code&gt; loop is the latest for-loop in the JavaScript world that will help developers iterate over iterables such as arrays, strings, maps and sets with lesser and cleaner code. It also improves code readability with its focused syntax. &lt;/p&gt;

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

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>es6</category>
    </item>
    <item>
      <title>Reverse a String with JavaScript</title>
      <dc:creator>Runo-saduwa</dc:creator>
      <pubDate>Thu, 01 Nov 2018 17:15:38 +0000</pubDate>
      <link>https://dev.to/runosaduwa/reverse-a-string-with-javascript-1g4d</link>
      <guid>https://dev.to/runosaduwa/reverse-a-string-with-javascript-1g4d</guid>
      <description>&lt;p&gt;Today marks my 10th month anniversary in software development and with my little experience i must admit that one of the ways of effectively assessing the depth of your knowledge in a programming language is by solving algorithms, that explains why most tech companies test applicants with algorithms. Solving algorithms will train you on how to manipulate data and as we all know, data is the basis of programming and your ability to manipulate data gives you the power to solve problems.&lt;/p&gt;

&lt;p&gt;This is my first post here on Dev and i will like to keep it simple. I'm dedicating this post to every developer who is willing to learn how to Reverse a string. Very Basic!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;I Have Two ways of Solving this&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;As we already know, In programming there are  several roads to one destination. the only differences between these roads is the ease at which it could get you to your destination. In this case i have two roads/ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The not so straight-forward way: Using the for loop&lt;/li&gt;
&lt;li&gt;The straight-forward way: Using Array methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The not so straight-forward way: Using the for loop&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Ok so here we go, the first thing we'll do is to make a function to contain our code, this should be done to make the code reusable and clean. So here we'll simply name our function &lt;code&gt;Reverse&lt;/code&gt; and pass in a parameter that will represent the string, lets name the parameter &lt;code&gt;str&lt;/code&gt;.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;      &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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; Your code should look like this. Great!, we're making progress.&lt;/p&gt;


&lt;p&gt;Now lets fill our function block with some logic.&lt;/p&gt; 


&lt;p&gt; By using a loop, we will simply create an array from the string, by using&lt;br&gt;
   the &lt;code&gt;split()&lt;/code&gt; method and we'll store the the array in a variable called &lt;code&gt;arr&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;     &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: we inserted an empty string in the parentheses to split the characters (incuding white space) individually.&lt;/p&gt;


&lt;p&gt;Next up, we need a variable to store the reversed word after the looping is completed. so lets declare a variable named &lt;code&gt;reversed&lt;/code&gt; and assign an empty string to this value!&lt;/p&gt;
&lt;br&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversed&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, where the magic happens!, we're going to set our loop to run from the end of the array to the beginning of the array! this could be tricky, but watch close, you'll get it.&lt;/p&gt;


&lt;p&gt;in this case we'll use a for loop and remember our for loop takes in 3 parameters.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the initializer: We are starting our loop from the back, so our initializer which is &lt;code&gt;i&lt;/code&gt; in this case is assigned to the index value of the last element in the array!
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="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;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lenght&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;N.B&lt;/strong&gt;: Taking &lt;code&gt;1&lt;/code&gt; out of the total length of an array will give us the index number of the last element because arrays start count from &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the Condition: the condition if simply, if &lt;code&gt;i&lt;/code&gt; is greater than or equal to &lt;code&gt;0&lt;/code&gt;, then the loo should keep running!;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Decrement: This part tells the i the next direction to take, in this case i is decreasing because we are looping from the last to the first element!
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;lets put all of this together in our for loop and fix the for loop in the &lt;code&gt;Reverse&lt;/code&gt; function!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lenght&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;finally, all we need to do is to append &lt;code&gt;arr[i]&lt;/code&gt; to reversed, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;outside the for loop block, return reversed and your final code should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;//If every thing went well then Reverse('runo') must return `onur`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;The straight-forward way: Using Array methods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Here, we'll simply chain three methods to the string.&lt;/p&gt;

&lt;p&gt;To achieve this we'll declare a variable called reversed and apply the following  steps to it&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first we'll apply the &lt;code&gt;split('')&lt;/code&gt; method to the string to form an array of individual string charaters&lt;/li&gt;
&lt;li&gt;then we'll chain the &lt;code&gt;reverse()&lt;/code&gt; method to the &lt;code&gt;split('')&lt;/code&gt; method to make the array reverse.&lt;/li&gt;
&lt;li&gt;then we'll chain &lt;code&gt;join('')&lt;/code&gt; to &lt;code&gt;reverse()&lt;/code&gt; method and finally&lt;/li&gt;
&lt;li&gt;return &lt;code&gt;reversed&lt;/code&gt;!
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;


   &lt;span class="nx"&gt;Reverse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Runo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//onuR&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Woo hoo!!!, this looks much cleaner and depicts that you actually know the language more!, so i guess everyone loves the straight forward way!&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this!, i will be dropping solutions to different type of algorithms (basic, intermediate and advanced), so watch out!&lt;/p&gt;

&lt;p&gt;Happy halloween and Happy Coding!&lt;/p&gt;

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