<?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: Sandra Spanik</title>
    <description>The latest articles on DEV Community by Sandra Spanik (@sanspanic).</description>
    <link>https://dev.to/sanspanic</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%2F569219%2F418b7e5f-ad9c-404c-9487-15c568e0b944.png</url>
      <title>DEV Community: Sandra Spanik</title>
      <link>https://dev.to/sanspanic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanspanic"/>
    <language>en</language>
    <item>
      <title>5 Things That Might Surprise You About Your First Software Engineering Job</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Thu, 28 Oct 2021 17:39:43 +0000</pubDate>
      <link>https://dev.to/sanspanic/5-things-that-might-surprise-you-about-your-first-software-engineering-job-28mj</link>
      <guid>https://dev.to/sanspanic/5-things-that-might-surprise-you-about-your-first-software-engineering-job-28mj</guid>
      <description>&lt;p&gt;So you've spent the last few months navigating the treacherous interview seas and have eventually emerged employed. Congratulations! Whilst getting your foot in the tech door might be the end of a long road, it also marks the beginning of a hopefully even longer one, one accompanied by its own, unique set of challenges. &lt;/p&gt;

&lt;p&gt;In this article I will outline 5 things I learned over my first half year as a software engineer that I found surprising. Of course, everyone's experience will be unique based on their background and the nature of the role they've accepted, but I believe the points below are general enough to apply to most freshly minted paid developers. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. The codebase is intimidating
&lt;/h2&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%2F667h6khphytq3vp7iq7u.gif" 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%2F667h6khphytq3vp7iq7u.gif" alt="codebase being intimidating"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And I mean truly, deeply, gut-wrenchingly intimidating. I can pretty much guarantee that the first time you examine the codebase, you'll have no idea what's going on. Your mind will be occupied by vast swathes of cluelessness and panic, punctuated by the occasional impostor-syndrome-esque thought here or there. &lt;strong&gt;If you don't cry at least once during your first few weeks, your stoicism rivals that of Seneca.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Perhaps you've only learned JavaScript, whereas the codebase is in TypeScript, perhaps you're encountering a library (or 53) you've never heard of before or using an exotic framework the workings of which you cannot even begin to fathom. Perhaps your eyes are widening as you first dip your toes into AWS at the sheer number of otherworldly sounding services they offer, or perhaps you are exasperating over GCP's inscrutable UI. Or perhaps, as was the case for me, you're experiencing all of above simultaneously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is all okay and normal, and you should seek comfort in the knowledge that even seasoned developers struggle in the first months after changing a job.&lt;/strong&gt; It takes a while to build up company-specific domain knowledge that allows you to understand how everything links up together. Have faith - the impossible will eventually come to pass and you'll one day realise that you've learned enough to start making meaningful, albeit small, contributions to the codebase. I promise!&lt;/p&gt;

&lt;p&gt;If you're anything like me, you'll then explain your mini-breakthrough to your colleagues in way too much detail, enthusiastic and wide-eyed, and receive minimal reactions, because the task you're taking pride in is one they could literally do in their sleep, so they probably don't even realise you're currently boasting. But that's okay. You do you. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Expectations are low
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/fUZHXuE94BN2wtSbUS/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/fUZHXuE94BN2wtSbUS/giphy-downsized-large.gif" alt="https://media.giphy.com/media/fUZHXuE94BN2wtSbUS/giphy-downsized-large.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thankfully, the expectations placed upon you are likely to be in line with just how useless you feel. You know nothing, your colleagues know that you know nothing, and your manager, too, is in on the secret.&lt;/p&gt;

&lt;p&gt;The skill level required to enter a software development profession as a junior is relatively low compared to other professions - you largely need to demonstrate your knowledge of a few programming languages and your enthusiasm for learning. It's as if you were hired as a doctor based on knowing the anatomy of the left hip and right arm and having successfully administered a few band-aids before.&lt;/p&gt;

&lt;p&gt;During my interview, I asked my manager how she'd define success in my first year in the role, to which she replied she'd basically expect me to be largely learning and figuring things out throughout the entirety of the first year. &lt;strong&gt;In any reasonable workplace, your senior team members will be ready and willing to help you find your footing.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Your standard workplace will not demand that you conduct large chunks of independent work until you are ready. I have to admit that this feels frustrating to me - in an ideal world, I'd already know the tech stack intimately and be able to make large, independent contributions to the codebase. But in reality, I still have to rely on my colleagues to make significant changes, especially when it comes to data engineering and infrastructural work. &lt;/p&gt;

&lt;p&gt;And when I say I rely on my colleagues, what I really mean is that we set up pair programming sessions to work through the challenging tasks together. For me, pairing has been integral to developing new skills. &lt;strong&gt;There's a balance to strike here - too much pairing will drain either party, but a reasonable amount will support the junior's learning while solidifying the senior's skillset.&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Communication is key
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/SvM08Tgr1YeCOyWPZb/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/SvM08Tgr1YeCOyWPZb/giphy.gif" alt="https://media.giphy.com/media/SvM08Tgr1YeCOyWPZb/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Software engineering is a highly collaborative profession and as such you will be in constant close contact with your team. Being able to admit when you don't know something, being able to ask for help, and being able to voice any additional support needs you might have are all qualities that will make your life easier. &lt;/p&gt;

&lt;p&gt;It can be intimidating to bring up concerns or to admit to struggling with a task. But unless your colleagues are superhuman and possess the skill of telepathy, which is even rarer than the mythical skill of exiting vim without using google, the only way things can improve is if everyone is on the same page. &lt;strong&gt;Get comfortable with asking for help.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This can be especially tricky in a work-from-home context, where as a beginner you might feel completely isolated with nobody physically around to ask for assistance. But if you're working remotely, communication becomes even more important, since in the absence of spending time together and socialising, your colleagues won't have the chance to pick up on you having a tough time unless you make this explicit. &lt;strong&gt;I've tried to live by the adage that over-communicating is better than under-communicating, and it's served me really well so far.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;You have to be your own biggest advocate and try to make sure that you have everything in place that you might need to eventually grow into a valuable and knowledgeable team member. Most companies will have structures in place that will allow you to feed back your needs to the team, for example via retros or debriefs. But it will be your own responsibility to use this opportunity fully and speak up for yourself. After all, it's something nobody else is able to do on your behalf. &lt;/p&gt;

&lt;h2&gt;
  
  
  4. Learning is non-linear
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1kenyYNFG9wTUyHMjk/giphy-downsized-large.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1kenyYNFG9wTUyHMjk/giphy-downsized-large.gif" alt="https://media.giphy.com/media/1kenyYNFG9wTUyHMjk/giphy-downsized-large.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you've come straight out of a bootcamp or an academic degree, you might find that the way in which you are now expanding your knowledge starkly differs from what you're used to. It's likely that you will no longer come across new topics in an organised, linear fashion, but instead encounter new, seemingly unrelated problems every day. An exception to this might be graduate programs or internships at large organisations. &lt;/p&gt;

&lt;p&gt;But in most medium or small companies, &lt;strong&gt;you will no longer be spoon-fed information in the exact order it's deemed most accessible by teaching experts.&lt;/strong&gt; There will be no carefully crafted tutorials on how your internal tech stack works and interlinks. You will have to go searching for relevant material online, read a lot of documentation and ask your colleagues many questions. It's now up to you to identify where you lack the basic building blocks you need to master a technology, and to go fill these gaps independently. &lt;/p&gt;

&lt;p&gt;As someone who went to a 9-month bootcamp which encouraged us to build lots of applications independently, I was used to producing a shiny new app every month or so, from scratch to finish. It felt like I was making massive leaps and continuously absorbing the maximum amount of information my brain would allow me to store. &lt;/p&gt;

&lt;p&gt;Nowadays, I feel like my pace has slowed down significantly - for one, the tools I'm learning are trickier to master, and often send me down a rabbit hole of other concepts I need to understand before I can fully comprehend the problem at hand - my own brain's private version of npm dependency hell. Secondly, once you find a solution to your problem, you are likely to have other sprint priorities to return to, and will as such be forced to stop exploring the subject. This means your learning style will likely change from continuous, long chunks of deep subject exploration to discrete, smaller bits and pieces here and there. &lt;/p&gt;

&lt;p&gt;This is not to say I haven't learned much over the last half year - the opposite is true. It's just that the learning has been more incremental and less organised. I've really benefited from documenting everything I've learned and taking notes on how I solve certain issues. More likely than not, the same issues will resurface elsewhere, so having notes to rely on instead of my own leaky memory has been super useful. &lt;/p&gt;

&lt;h2&gt;
  
  
  5. It's not just about writing code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ekjmhJUGHJm7FC4Juo/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ekjmhJUGHJm7FC4Juo/giphy.gif" alt="https://media.giphy.com/media/ekjmhJUGHJm7FC4Juo/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Code comprehension
&lt;/h4&gt;

&lt;p&gt;Say goodbye to visions of yourself banging out line after line of novel code from 9 to 5. &lt;strong&gt;The reality is that most days, you will end up reading more code than you write.&lt;/strong&gt; You will spend ample time building a mental model of how a specific part of the codebase works, until you eventually distil your newfound knowledge into a few lines of code that achieve the required change. These will then go through a code review and if deemed acceptable, become part of the codebase. &lt;/p&gt;

&lt;h4&gt;
  
  
  Algo-what?
&lt;/h4&gt;

&lt;p&gt;While you're at it, you can also say goodbye to sorting algorithms, hacker rank problems and Big O complexity. &lt;strong&gt;Be prepared to not encounter problems that require a ton of algorithmic thinking&lt;/strong&gt;, at least for now, while you're still a baby dev. This is not to say there is no value in continuously practicing these in your own time - if you have spare energy, by all means, do. But don't expect the job to contain a lot of opportunities to implement the types of algorithmic problems most employers still ask during interviews. Weird, it's almost as if the recruitment process doesn't actually reflect the job accurately... 🧐&lt;/p&gt;

&lt;h4&gt;
  
  
  Discovery
&lt;/h4&gt;

&lt;p&gt;Not all tasks are glamorous. &lt;strong&gt;By this I mean, not all tasks involve solving interesting problems programatically.&lt;/strong&gt; Sometimes, your job will be to read frequently incomplete and badly written documentation to figure out how the tools you are using work. Setup, configuration, and similar, arguably boring preparatory tasks, are part of the deal - especially when starting new projects or breaking novel ground and doing discovery surrounding existing projects. I suppose that this is the price we pay to earn a decent salary and have fun coding whilst tackling the other, less config-heavy tasks. &lt;/p&gt;

&lt;h4&gt;
  
  
  Meetings
&lt;/h4&gt;

&lt;p&gt;Expect many meetings. Sprint planning, retros and daily stand-ups. Making sure there's alignment within your team, as well as cross-team alignment. Socials, if you're lucky. In any case, seeing people in 2D on a screen will quickly become part of your daily routine.&lt;/p&gt;

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

&lt;p&gt;Being a software engineer means being in constant contact with people. It's a highly collaborative discipline, and you will benefit from being able to communicate well. The codebase will initially seem indecipherable, but be patient and kind to yourself - things will eventually click. Your colleagues will help you, but you should also be prepared to do a lot of research and learn new tools independently. Be ready to spend more time reading code than writing it. &lt;/p&gt;

&lt;p&gt;Have my first 6 months as a software engineer been at times arduous and challenging? Yep. &lt;strong&gt;Has it all been worth it? Absolutely.&lt;/strong&gt; In my own, biased, opinion of course. &lt;/p&gt;

</description>
      <category>career</category>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The JavaScript Reduce Method</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Wed, 21 Jul 2021 20:48:04 +0000</pubDate>
      <link>https://dev.to/sanspanic/the-javascript-reduce-method-3j8l</link>
      <guid>https://dev.to/sanspanic/the-javascript-reduce-method-3j8l</guid>
      <description>&lt;p&gt;Until recently, the only thing I've ever successfully reduced was myself - to tears. Much like the world's billionaires have recently embarked on journeys to shoot their wealthy bottoms to outer space, so, too, have I embarked on an epic adventure to understand the reduce method. Would you like to accompany me on my journey to finally, once and for all, understand the notorious, the dreaded, the one-and-only reduce method? Great. Welcome on board Rocket 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%2Fu38kd3wlx4blbrst49s4.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%2Fu38kd3wlx4blbrst49s4.png" alt="Bezos and a rocket looking evil"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the reduce method?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Javascript comes with a bunch of inbuilt array methods designed to make our lives easier. They provide out-of-the-box, frequently needed functionality for iterating through or manipulating arrays in specific ways. There's quite a few of them and whilst it's completely unnecessary to remember them &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array" rel="noopener noreferrer"&gt;all&lt;/a&gt;, it's a good idea to have some solid intuitions about what can be achieved using them. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;, the reduce() method executes a callback function (that you provide) on each element of the array, resulting in a single output value. Apart from the callback function, it can also take in an initial value.&lt;/strong&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;//reducer is the callback function, initialValue is the optional second param&lt;/span&gt;
&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt; &lt;span class="p"&gt;[,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;The reducer function&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The callback function takes four arguments,&lt;/strong&gt; but the last two can frequently be omitted, depending on what we want to achieve. The function is then applied to each element in the array, eventually returning a single value. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Accumulator&lt;/strong&gt; - this accumulates the reducer function's return values&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Current Value&lt;/strong&gt; - the current element being processed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Current Index&lt;/strong&gt; (optional) - index of the current element being processed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source Array&lt;/strong&gt; (optional) - the array we are calling the reduce method on&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;){}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This can all sound very confusing, so let's break it down and examine the syntax. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's assume we want to write a function that adds up all items in an array and returns their sum.&lt;/strong&gt; The initial array we want to sum is the following. Let's ignore the fact it clearly adds up to 10 and pretend our mathematical ability is low enough to require us to find a programmatic solution to what we perceive to be an impossible numeric challenge.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now let's look at how to apply the reduce method. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;//define the reducer function, provide it with its first 2 parameters&lt;/span&gt;
&lt;span class="c1"&gt;//returns the sum of the accumulator and currentValue&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;

&lt;span class="c1"&gt;//apply reducer function to array&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;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculateSum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Above, we've told the reducer function to return the sum of the accumulator and the current value being processed. This means that as the reducer iterates through the array, each new number will be added to an ever-increasing sum held in the accumulator. Still confusing? I agree. Let's add in some console.logs to understand how the process executes. &lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;Throughout the article, I will post images to show how the accumulator and currentValue of the callback function change. I will then explain the image using words, which might or might not be useful for you. If you're a visual learner, you might find the images on its own more useful and feel confused by the text. Feel free to skip the bits that are not useful to your particular learning style.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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="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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accumulator: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;accumulator&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;currentValue:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&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="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculateSum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&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%2F8g7huu46dyq333qb749j.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%2F8g7huu46dyq333qb749j.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On the first iteration, the accumulator is the first item of the array, 1. The currentValue, or the item being processed, is the following item, 2. As we apply the reducer function to 2, the reducer returns the sum of the accumulator, 1 and the currentValue, 2. &lt;/li&gt;
&lt;li&gt;The return value of the reducer, 3, becomes the new accumulator. The currentValue shifts to the next item in the array, which happens to also be 3. The function to add the accumulator to the currentValue is applied to the currentValue of 3, which makes 3 + 3 and results in 6. &lt;/li&gt;
&lt;li&gt;6 therefore becomes the new accumulator. The next item in the array, the currentValue, is  now 4. The reducer that adds up the accumulator and currentValue now gets applied to 4. 6 + 4 is 10, and because there are no more items in the array, this becomes the final return value. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Phew. Turns out, not only is this array method hard to understand, it's also hard to describe. If my words confused you, I encourage you to step through the image line by line in your own time. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: By the way, this is not a common real-world use case for the reduce method. If all we want to do is sum an array of numbers, we might as well just use a for loop or forEach. Nevertheless, using reduce in this way serves as a good illustration of how the method works. We will encounter a few such 'bad-use-but-good-explanation-cases' over the course of this article. &lt;/p&gt;

&lt;h2&gt;
  
  
  Initial Value
&lt;/h2&gt;

&lt;p&gt;We can also tell our reduce method to initialise the accumulator at an arbitrary value of our own choosing, by passing in the optional parameter of initialValue. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Let's recycle above example. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculateSum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;accumulator&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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="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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;accumulator: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;accumulator&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;currentValue:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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;accumulator&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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 we tell the reduce method to initialise the accumulator at 10&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;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculateSum&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the previous version of this example, the first accumulator was 1, which is the first value of the array. Here, we override this value by adding a second argument to the reduce method, the initialValue of 10. 10 now becomes our first accumulator, and the reducer is applied to the first item in the array. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd63np4pt7it89cvw14gw.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%2Fd63np4pt7it89cvw14gw.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's a summary of how passing in the optional initial value parameter affects the execution of the reduce method. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;initialValue&lt;/th&gt;
&lt;th&gt;accumulator&lt;/th&gt;
&lt;th&gt;currentValue&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;not passed&lt;/td&gt;
&lt;td&gt;&lt;code&gt;accumulator = array[0]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;currentValue = array[1]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;passed&lt;/td&gt;
&lt;td&gt;&lt;code&gt;accumulator = initialValue&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;currentValue = array[0]&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Setting the initial value something other than a number, (e.g. an empty array or object) allows us to do some neat stuff with our reducers. Let's walk through a couple of examples. &lt;/p&gt;

&lt;h2&gt;
  
  
  1. Counting using reduce
&lt;/h2&gt;

&lt;p&gt;Let's say we're looking to write a function that takes in a string and returns an object with a letter count for the given string. If our string was "save the bees" our desired return value would be&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{ s: 2, a: 1, v: 1, e: 4, " ": 2, t: 1, h: 1, b: 1 }&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🚫🚫🚀🚀 less rockets, more bees pls&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;letterCountReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&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="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&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;acc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&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;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;acc&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 accumulator is initialised as an empty object&lt;/span&gt;
&lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letterCountReducer&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;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;image showing the beginning of the execution order of above process&lt;/em&gt;&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%2Fxon11imq3o7x4d4cax66.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%2Fxon11imq3o7x4d4cax66.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Because we passed in the initial value of an empty object, the accumulator is initialised as an empty object.&lt;/li&gt;
&lt;li&gt; As we iterate over the array, we can check whether each letter exists as a key in the accumulator object. If it does, we increment it by 1, if it doesn't, we initialise it with a value of 1. &lt;/li&gt;
&lt;li&gt;We return the new accumulator that now accounts for the letter we just iterated over, and move on. Eventually we'll return an accumulator that contains an object with all the letters accounted for. &lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  2. Flattening arrays using reduce
&lt;/h2&gt;

&lt;p&gt;Let's assume we have an array of arrays. Three types of animals, dying to be together, separated by indomitable array walls. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;//BOO! An unnatural habitat&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;zoo&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;🐇&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;🐇&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;🐇&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;🐷&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;🐷&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;🐷&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;🐻&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;🐻&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;🐻&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;How do we break them free? &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;flatten&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;animalArray&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;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;animalArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;zoo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flatten&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;span class="c1"&gt;//returns ["🐇", "🐇", "🐇", "🐷", "🐷", "🐷", "🐻", "🐻", "🐻"]&lt;/span&gt;
&lt;span class="c1"&gt;//YAY! A natural habitat!&lt;/span&gt;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&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%2Fzuqxewzndgg432rtdd5d.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%2Fzuqxewzndgg432rtdd5d.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We provide an empty array as the accumulator. &lt;/li&gt;
&lt;li&gt;The reducer concatenates the first current value, here named animalArray, to the empty accumulator. We return this new array, now filled with 3 bunnies. &lt;/li&gt;
&lt;li&gt;This becomes the new accumulator, to which we now concatenate the next currentValue, or animalArray. The second item in the original array is an array of pigs. We return the new accumulator consisting of bunnies and pigs, and move on to the bears. The accumulator is now an array of bunnies and pigs. To this, we concatenate the current value - the bear array. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; While this example serves to illustrate the workings of the reduce method, in practice, I'd opt for the arr.flat() method which does exactly what it says on the tin. &lt;/p&gt;
&lt;h2&gt;
  
  
  3. Deduplicating arrays using reduce
&lt;/h2&gt;

&lt;p&gt;Let's assume we have an array with duplicates and want to end up with an array of unique values instead. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;//initial arr&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrOfDupes&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;🚀&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;🚀&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;🚀&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;🌍&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;//desired output&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🚀&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;🌍&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;dedupe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentValue&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentValue&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;acc&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="nx"&gt;dedupedArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;arrOfDupes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dedupe&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;h3&gt;
  
  
  Explanation
&lt;/h3&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%2Frhuekdgny7rb0pk5uo5v.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%2Frhuekdgny7rb0pk5uo5v.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We start with the initial value of an empty array, which becomes our first accumulator. &lt;/li&gt;
&lt;li&gt;As the reduce method iterates over the array, the callback function gets applied to each item in the array. It checks for the absence of the current value from the accumulator. If this is the case, the current value gets pushed into the accumulator. &lt;/li&gt;
&lt;li&gt;The accumulator gets returned, either unchanged or with an additional unique value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: While this example serves to illustrate the inner workings of the reduce method, in practice, I'd opt for deduplicating an array of primitives by using Sets, which is a more performant approach. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="nx"&gt;dedupedArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)];&lt;/span&gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  4. Grouping items using reduce
&lt;/h2&gt;

&lt;p&gt;Let's assume we want to group an array of objects by property. We start with an array of objects and end up with an object that includes two arrays where the objects are grouped by a selected property. &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;//initial array of objects to be grouped&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;climateBehaviours&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="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Recycle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cycle everywhere&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Commute to work via plane&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;70&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Replace beef with veg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Build a rocket for space tourism&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;//desired output: an object with two groups&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;goodClimateBehaviours&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;span class="p"&gt;...],&lt;/span&gt; &lt;span class="c1"&gt;// greenPoints &amp;gt;= 0&lt;/span&gt;
  &lt;span class="na"&gt;badClimateBehaviours&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;span class="p"&gt;...],&lt;/span&gt;  &lt;span class="c1"&gt;// greenPoints &amp;lt; 0&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Let's code this up. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;//reducer function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;groupBehaviour&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentObj&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="nx"&gt;currentObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greenPoints&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;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;goodClimateBehaviours&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentObj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;badClimateBehaviours&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;currentObj&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;acc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//initial value &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialGrouping&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;goodClimateBehaviours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;badClimateBehaviours&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;span class="c1"&gt;//applying the reduce method on the original array&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;groupedBehaviours&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;climateBehaviours&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;groupBehaviour&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialGrouping&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In bad news for the Musks, Bezoses and Bransons of this world, this is what we end up with. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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;groupedBehaviours&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;goodClimateBehaviours&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;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Recycle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cycle everywhere&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Replace beef with veg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&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="nx"&gt;badClimateBehaviours&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;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Commute to work via plane&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;70&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Build a rocket for space tourism&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;greenPoints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;500&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;h3&gt;
  
  
  Explanation
&lt;/h3&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%2Fgb4195cskr40pmq5uukn.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%2Fgb4195cskr40pmq5uukn.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The initial value is an object with two properties, goodClimateBehaviours and badClimateBehaviours. This is our first accumulator. &lt;/li&gt;
&lt;li&gt;The callback reducer function iterates over the array of objects. Each time, it checks whether the current object has greenPoints greater than 0. If so, it pushes the object into accumulator.goodClimateBehaviours, otherwise the object is pushed to accumulator.badClimateBehaviours. The accumulator is then returned. &lt;/li&gt;
&lt;li&gt;An accumulator eventually containing all objects will be returned as the final return value.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  5. Manipulating more complex data structures using reduce
&lt;/h2&gt;

&lt;p&gt;In the real world, the power of reduce gets harnessed most commonly when manipulating more complex data structures. Let's say we have an array of objects with an id, description and outcomes array, where each outcome can be desirable or not. We want to transform this array into a single object that looks quite different. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;climateActions&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="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;space_tourism&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;build rockets for space tourism&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;outcomes&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;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rich people can go to space&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;is pretty cool&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;increased emissions&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;investment diverted from green energy to space tourism&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;trees_4_lyf&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;stop burning down the amazon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;outcomes&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;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;air for all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;our kids might live&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reduce threat of imminent extinction&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;make greta happy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;make bolsonaro sad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;isDesirable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;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;Our aim is to transform this array into a single object which has the id as keys, and an object with arrays of good outcomes and bad outcomes, as shown below. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;climateInitiatives&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="s1"&gt;space_tourism&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="na"&gt;badOutcomes&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;rich people can go to space&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;increased emissions&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;investment diverted from green energy to space tourism&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="na"&gt;goodOutcomes&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;is pretty cool&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;trees_4_lyf&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="na"&gt;badOutcomes&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;make bolsonaro sad&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;goodOutcomes&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;air for all&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;our kids might live&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;reduce threat of imminent extinction&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;make greta happy&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;span class="p"&gt;};&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Here's one way to implement this transformation, using reduce. &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;reducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentObj&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newAcc&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;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentObj&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="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;badOutcomes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="na"&gt;goodOutcomes&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;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;currentObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outcomes&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;outcome&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isDesirable&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;newAcc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentObj&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="nx"&gt;goodOutcomes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;newAcc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;currentObj&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="nx"&gt;badOutcomes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;outcome&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;outcome&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;newAcc&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="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;climateActions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&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;We could also, instead of using the map method, use a reduce within the reduce, but we might break the matrix in doing so. 🤯&lt;/p&gt;

&lt;h3&gt;
  
  
  Explanation
&lt;/h3&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%2Fkstrudvn1rvqyiqpevnd.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%2Fkstrudvn1rvqyiqpevnd.png" alt="Screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The first accumulator is an empty object. The current value, named current object here, is the first object in the original array. &lt;/li&gt;
&lt;li&gt;The reducer function initialises a new variable, newAcc. newAcc is an object, with the spread of the current (still empty) accumulator. We assign a new property to newAcc, with the key being the current object's id, and the value being an object with the bad and good outcomes arrays.  &lt;code&gt;[currentObj.id]: { badOutcomes: [], goodOutcomes: [] }&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We then map over the current object's outcomes array and depending on whether the outcome is desirable, push it into or new variable newAcc's outcomes array. &lt;/li&gt;
&lt;li&gt;We return the newAcc, which becomes the acc on the next round of iteration, so when we spread it, we don't lose its contents. &lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;What have we learned? Hopefully, the reduce method (&lt;em&gt;and also that I am clearly not a huge fan of billionaires squandering resources on the selfish pursuit of space travel at a time when we should all focus on preventing catastrophic global heating, but that's just my opinion&lt;/em&gt; 🔥). &lt;/p&gt;

&lt;p&gt;Reduce is undoubtedly one of JavaScript's more tricky inbuilt methods. But as is the case with most coding, the best way to truly understand it is to practice. If the examples in this article made sense - great! If not - also great, one more opportunity to play around and practice until things click. And I promise, they eventually will. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, let's go and reduce some code&lt;/strong&gt;. &lt;em&gt;Also our emissions&lt;/em&gt;. 🍃&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>programming</category>
    </item>
    <item>
      <title>Blaming Git Blame</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Wed, 23 Jun 2021 18:16:09 +0000</pubDate>
      <link>https://dev.to/sanspanic/blaming-git-blame-1f4o</link>
      <guid>https://dev.to/sanspanic/blaming-git-blame-1f4o</guid>
      <description>&lt;p&gt;In this article I make a case for renaming the feature &lt;code&gt;git blame&lt;/code&gt; to a neutral equivalent (e.g. &lt;code&gt;git author&lt;/code&gt; or &lt;code&gt;git inspect&lt;/code&gt;). I argue that the use of &lt;code&gt;git blame&lt;/code&gt; primes workplaces and teams for blame culture and contributes to unhelpful feelings of shame. The language we use shapes our cognition, feelings and behaviours in small but systematic ways, and it is for this reason that I argue renaming the otherwise useful feature &lt;code&gt;git blame&lt;/code&gt; is long overdue. I also investigate the source code of git in an attempt to understand how the feature got introduced, and connect with its author to find that he, too, wishes the feature was named differently. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is git?
&lt;/h2&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%2F97ye7ey047ojohienec9.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%2F97ye7ey047ojohienec9.png" alt="Git logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git is an open source version control tool with widespread adoption that allows individuals to track changes to files over time and revert back to previous versions of files at any time. It is extremely useful for collaboration and has become the de-facto standard for software engineering teams. While there are alternative version control systems, many companies consider a basic command of git a pre-requisite for employment. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is git blame? 😳
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://git-scm.com/docs/git-blame/2.31.0" rel="noopener noreferrer"&gt;Git blame&lt;/a&gt; is a git command which reveals what revision and author last modified each line of a file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I was first shown the feature, I chuckled nervously at the discovery. Being new to tech, I generously allow for the possibility that my code might not yet be, objectively, what one would call "the shit". Naturally, I immediately imagined my colleagues repeatedly invoking my name using &lt;code&gt;git blame&lt;/code&gt;, subconsciously adding the tiniest bit of additional frustration to an ever-growing stinking pile of frustrations upon each discovery of me as the culprit. In 21st century language, I'd summarise my feelings about learning of &lt;code&gt;git blame&lt;/code&gt;as follows: 👀. &lt;/p&gt;

&lt;p&gt;Whilst my instinctual reaction was that of pre-emptive shame creeping in, it was quickly countered by some good old rational thinking. I feel safe in my workplace, knowing that my colleagues aren't on the hunt to assign blame for mistakes, and that my organisation values collaboration over rockstar developing. &lt;/p&gt;

&lt;p&gt;I was told that the main utility of the feature is not enabling team members to blame each other for their poor code contributions, but &lt;strong&gt;enabling individuals to find out who would be the best person to ask about a specific part of a codebase&lt;/strong&gt;. The ability to quickly identify the author of a given part of the codebase for follow-up questions is handy, and saves time. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're asking yourself, why would the feature be named &lt;code&gt;blame&lt;/code&gt; instead of &lt;code&gt;author&lt;/code&gt;, when it primarily gets used to identify the code's author, then you and I are asking ourselves the same question.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Git blame is harmful 🤕
&lt;/h2&gt;

&lt;p&gt;Let's assume we agree that &lt;code&gt;git blame&lt;/code&gt; shouldn't get used with the intent of assigning blame within teams. A big assumption to make, that I bet some teams with archaic or authoritarian work philosophies would disagree with. But philosophical differences regarding effective collaboration are beyond the scope of this article. &lt;/p&gt;

&lt;p&gt;Okay, so we're assuming we all agree - let's not blame each other and instead primarily use &lt;code&gt;git blame&lt;/code&gt; to find the code's author in a blame-free context. Great. But even so, 2 issues remain: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why should the onus be on us developers to do mental gymnastics and internally rebrand &lt;code&gt;git blame&lt;/code&gt; as &lt;code&gt;git author&lt;/code&gt;, when in fact, the feature itself could just be named &lt;code&gt;git author&lt;/code&gt; in the first place? &lt;/li&gt;
&lt;li&gt;Even though we can agree to see beyond its literal meaning, the naming of the feature still continues to affect us in systematic ways.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is because &lt;strong&gt;language subconsciously shapes the way we think, feel and behave.&lt;/strong&gt; Repeated exposure to the word blame in a work context is harmful. It feels implausible that in today's climate, where we rightfully pay attention to our language more than ever, a feature like &lt;code&gt;git blame&lt;/code&gt; should be allowed to peacefully continue existing and priming workplaces for blame culture.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Language measurably shapes our cognition 🧠
&lt;/h2&gt;

&lt;p&gt;The language we use demonstrably influences how and what we think. For example, existing cross-cultural differences in how we perceive time, distance and size can be traced back to how different languages construct these abstract ideas. Also, speakers of languages which use grammatical genders such as Russian or German are heavily influenced by the arbitrary grammatical gender of nouns. These speakers' visual representations of such nouns and their instinctive associations depend heavily on the noun's otherwise random gender. Even visual perception is not immune to the effect of language. For example, Russian speakers are better at distinguishing between shades of blue than English speakers because they have more words to describe them. You can read more about all of this &lt;a href="https://www.edge.org/conversation/lera_boroditsky-how-does-our-language-shape-the-way-we-think#:~:text=The%20fact%20that%20even%20quirks,affect%20our%20thinking%20is%20profound.&amp;amp;text=Language%20is%20central%20to%20our,way%20we%20live%20our%20lives." rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Language has a priming effect 🗣️
&lt;/h2&gt;

&lt;p&gt;Priming is a phenomenon whereby exposure to one stimulus influences a response to a subsequent stimulus, without conscious guidance or intention. For example, exposing someone to the word "yellow" will evoke a faster response to the word "banana" than it will to an unrelated word like "sofa". Priming takes place outside of our conscious awareness, but it plays an &lt;a href="https://www.verywellmind.com/priming-and-the-psychology-of-memory-4173092" rel="noopener noreferrer"&gt;important role&lt;/a&gt; in our daily lives. From influencing how we interpret information to our behaviour, priming can play a part in our perceptions, emotions, and actions. &lt;a href="https://alldgt.com/priming-in-marketing/" rel="noopener noreferrer"&gt;Marketers&lt;/a&gt;, advertisers and even social media engineers have sought to exploit this effect. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's reasonable to assume that seeing the word blame repeatedly primes us for negative affective responses.&lt;/strong&gt; If you are committing new code, thinking of the word "blame" is likely to introduce just the slightest bit of fear, shame or guilt. On the flip side, if you are the one investigating changes and see your colleague's name next to the word "blame", you will be more likely to actually assign blame to them and associate their name with a negative affective state. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/vX9WcCiWwUF7G/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/vX9WcCiWwUF7G/source.gif" alt="https://media.giphy.com/media/vX9WcCiWwUF7G/source.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let me pre-empt some questions a reader might have at this stage. &lt;/p&gt;

&lt;h2&gt;
  
  
  If it bothers you so much, why don't you just alias it?  ❄️
&lt;/h2&gt;

&lt;p&gt;I'm aware that git has a neat &lt;code&gt;alias&lt;/code&gt; feature that allows you to &lt;a href="https://www.atlassian.com/git/tutorials/git-alias" rel="noopener noreferrer"&gt;replace any command with another&lt;/a&gt;. Technically, nothing's stopping me from renaming &lt;code&gt;git blame&lt;/code&gt; to &lt;code&gt;git candyfloss&lt;/code&gt;. But the feature is ubiquitous and difficult to avoid, so creating an alias in my local device would barely reduce my exposure to it. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;image of VSCode blame extension&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjud22yeuxnc37frjiij.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%2Fbjud22yeuxnc37frjiij.png" alt="VSCode blame extension showing author's name next to the word blame"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are useful git extensions that display git blame, and even Github itself has a UI version of git blame that shows you the author and the name of the commit associated with each part of the codebase. According to the &lt;a href="https://insights.stackoverflow.com/survey/2020#technology-collaboration-tools-all-respondents" rel="noopener noreferrer"&gt;2020 Stackoverflow Annual Developer Survey&lt;/a&gt;, more than 82% of us use Github, so the word blame really is near impossible to escape.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;image of Github's blame interface (yes, this is what Github looks like in light mode)&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0uo42bwpsomysbz0erw4.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%2F0uo42bwpsomysbz0erw4.png" alt="github blame interface"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wmvocpsvftt8j9hijjn.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%2F4wmvocpsvftt8j9hijjn.png" alt="Github's blame interface"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  If it bothers you so much, why don't you just use git annotate? ❄️
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;git annotate&lt;/code&gt; is another git command with nearly the same functionality. Whilst &lt;code&gt;git annotate&lt;/code&gt; doesn't differ from the criticised feature &lt;a href="https://git-scm.com/docs/git-annotate" rel="noopener noreferrer"&gt;by much&lt;/a&gt;, it doesn't solve the issue for the exact same reasons described above. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Having justified why &lt;code&gt;git blame&lt;/code&gt; is worth discussing, let's now delve into its history.&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  What's to blame for git blame? 🔎
&lt;/h2&gt;

&lt;p&gt;Git was created in 2005 by none other than &lt;strong&gt;Linus Torvald, the creator of Linux&lt;/strong&gt;, who was at the time working on his operating system with a dispersed team of volunteer developers. Working remotely before it was cool, he was using the proprietary version control software BitKeeper, which was made available to his team for free. Until, one controversy later involving an engineer being accused of reverse-engineering the software, BitKeeper's founder Larry McVoy withdrew the agreement. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Torvalds&lt;/strong&gt; soon announced he would go on a week-long holiday, and in true vacation spirit, &lt;strong&gt;created the first version of the version control tool that 82% of today's nearly 27 million developers use,&lt;/strong&gt; probably all whilst reclining on a beach chair and sipping on a cold one. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;actual footage of Torvalds implementing git (probably)&lt;/em&gt;&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%2Fimages.unsplash.com%2Fphoto-1512552288940-3a300922a275%3Fixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26ixlib%3Drb-1.2.1%26auto%3Dformat%26fit%3Dcrop%26w%3D1351%26q%3D80" 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%2Fimages.unsplash.com%2Fphoto-1512552288940-3a300922a275%3Fixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26ixlib%3Drb-1.2.1%26auto%3Dformat%26fit%3Dcrop%26w%3D1351%26q%3D80" alt="https://images.unsplash.com/photo-1512552288940-3a300922a275?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;amp;ixlib=rb-1.2.1&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1351&amp;amp;q=80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git's success was a surprise to him. It's safe to say that carefully naming projects sensitively, especially those he never expected to take off in such spectacular fashion, wasn't Torvalds' priority nor inclination. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The in-joke was that I name all my projects after myself, and this one was named ‘Git’. Git is British slang for ‘stupid person’,” Torvalds tells us.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's right. Git is actually a British swear word. If you've previously noticed this and chuckled at the fact that git is eponymous with the swear word popularised by The Beatles and Ronald Weasley, the joke's on you - git's creator knew this full well. The &lt;a href="https://github.com/git/git#git---fast-scalable-distributed-revision-control-system" rel="noopener noreferrer"&gt;README&lt;/a&gt; of Git elaborates even further: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Git", the "stupid content tracker", can mean anything, depending on your mood&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Stupid. Contemptible and despicable. Simple. Take your pick from the dictionary of slang.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"Global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;"Goddamn idiotic truckload of sh*t": when it breaks.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Open source
&lt;/h2&gt;

&lt;p&gt;Git's maintenance continued to be led by one of the most active early contributors &lt;strong&gt;Junio Hamano&lt;/strong&gt;, who is said to remain somewhat of a benevolent dictator to the git community up to this day. It's important to note that git is by no means one man's toy. &lt;strong&gt;It is the result of a decade and a half of collaboration and hard work by an active and caring community.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Their &lt;a href="https://github.com/git/git/blob/master/CODE_OF_CONDUCT.md" rel="noopener noreferrer"&gt;Code of Conduct&lt;/a&gt; speaks of a community that is &lt;strong&gt;respectful and kind.&lt;/strong&gt; But the extent to which this is true is unclear to me because I am neither a contributor myself nor am I impervious to stories about the patriarch himself, Linus, occasionally telling contributors they should probably be &lt;strong&gt;retroactively aborted&lt;/strong&gt;. A man who enjoys to jokingly &lt;a href="https://www.youtube.com/watch?v=JZ017D_JOPY&amp;amp;ab_channel=TFiRTFiR" rel="noopener noreferrer"&gt;call out&lt;/a&gt; stupid people who write stupid patches for being so stupid that it's a surprise they've managed to find a tit to suck on as stupid babies, is not a man I associate with creating welcoming communities.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Torvalds letting us all know what he really thinks of our code contributions (probably)&lt;/em&gt;&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%2F903bvpcjyfxn65lkguf8.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%2F903bvpcjyfxn65lkguf8.png" alt="torvalds flipping the middle finger"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whilst I must admit that I personally enjoy his particular brand of dark humour, I'd advocate for being more mindful of the power dynamics we are all part of, because whether we like it or not, our words can have unintended harmful consequences. &lt;/p&gt;

&lt;p&gt;A theory started forming in my head: &lt;strong&gt;perhaps &lt;code&gt;git blame&lt;/code&gt; was the result of the same strain of dark humour?&lt;/strong&gt; Maybe a seemingly innocent but really quite insensitive joke that feels so on brand for the Linux creator's past? I say past here, because the man is apparently &lt;a href="https://thehackernews.com/2018/09/linus-torvalds-jerk.html" rel="noopener noreferrer"&gt;evolved now&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;I'd like to think that, having known the many millions of developers who'd come into contact with the concept of blame on a daily basis as a result of a mildly amusing joke, the naming of &lt;code&gt;git blame&lt;/code&gt; would have been reconsidered. &lt;strong&gt;I'd say, it's about time we retroactively abort it.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting to the bottom of git blame 🕵🏼‍♀️
&lt;/h2&gt;

&lt;p&gt;Spoiler alert: as you might have already guessed, astute reader, my naive assumption that &lt;code&gt;git blame&lt;/code&gt; started as a joke is, in fact, completely wrong. But let's dig into how I derived at this sobering conclusion. &lt;/p&gt;

&lt;p&gt;Thankfully, git is so spectacularly useful that I didn't have to stop at simply theorising about my burning question of how, when and why &lt;code&gt;git blame&lt;/code&gt; was introduced. &lt;strong&gt;The beauty of git itself being an open source project made with git, means that anyone can check out who authored which changes when.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In search of some answers, I put on my detective hat, raised a monocle to my eye, and downloaded Git's &lt;a href="https://github.com/git/git" rel="noopener noreferrer"&gt;source code repo&lt;/a&gt;. To search for the earliest introduction of the string "blame" into the codebase, I used &lt;code&gt;git log --all -p --reverse --source -S 'blame'&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;The first mention of "blame" I found was in the documentation intended for users migrating from CVS, a competing version control tool. The changed file, in classic Linus fashion, begins with the following sentence: "&lt;em&gt;OK, so you're a CVS user. That's ok, it's a treatable condition, and the first step to recovery is admitting you have a problem&lt;/em&gt;". Had programming not worked out for the man, standup comedy would have been a solid second choice. &lt;/p&gt;

&lt;p&gt;Here's the bit that features the word "blame". &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Author: Linus Torvalds &lt;a href="//mailto:torvalds@linux-foundation.org"&gt;torvalds@linux-foundation.org&lt;/a&gt;&lt;br&gt;
Date:  Wed Jun 8 13:19:31 2005 -0700&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;&lt;em&gt;So, something has gone wrong, &lt;strong&gt;and you don't know whom to blame&lt;/strong&gt;, and&lt;br&gt;
you're an ex-CVS user and used to do "cvs annotate" to see who caused&lt;br&gt;
the breakage. You're looking for the "git annotate", and it's just&lt;br&gt;
claiming not to find such a script. You're annoyed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Yes, that's right.  Core git doesn't do "annotate", although it's&lt;br&gt;
technically possible, and there are at least two specialized scripts out&lt;br&gt;
there that can be used to get equivalent information...&lt;/em&gt;&lt;/p&gt;



&lt;p&gt;The text suggests ex-CVS users were predicted to expect the command &lt;code&gt;git annotate&lt;/code&gt; to produce what we now know as the &lt;code&gt;git blame&lt;/code&gt; output, based on CVS itself supporting an &lt;code&gt;annotate&lt;/code&gt; command. Neither of the commands existed in git at the time (although now, they both do). &lt;/p&gt;

&lt;p&gt;At this point, it seemed to me like the jury was still out on whether the naming of &lt;code&gt;git blame&lt;/code&gt; was the result of a joke or an intentional, serious, naming decision. But from reading through the documentation, it started seeming more and more like &lt;code&gt;git blame&lt;/code&gt; was the result of a work ideology that starkly departs from mine, and embraces a culture where assigning blame is the norm and tolerance for mistakes is scant. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Still hungry for answers, I dug deeper and uncovered git's public &lt;a href="https://public-inbox.org/git/" rel="noopener noreferrer"&gt;mailing list archives&lt;/a&gt;.&lt;/strong&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  The real origin of git blame 💫
&lt;/h2&gt;

&lt;p&gt;In May 2005, a member of the git open source community sent an email, wondering how to replicate the CVS annotate feature. Linus replied saying that whilst he knows how to do it (obviously 💅), he's hoping someone else will, because he generally doesn't care about the feature enough. &lt;em&gt;So much for my Torvalds-joke hypothesis.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Junio Hamano came forward and implemented a slow yet working algorithm in Perl, which became the base of future &lt;code&gt;git blame&lt;/code&gt; implementations. Then, 2 people independently created their own versions - one of which became &lt;code&gt;git annotate&lt;/code&gt;, named consistently with SVN, and the other became &lt;code&gt;git blame&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;Here's the "guilty" commit.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Author: Fredrik Kuivinen &lt;a href="//mailto:frekui@gmail.com"&gt;frekui@gmail.com&lt;/a&gt;&lt;br&gt;
Date:   Tue Feb 21 00:40:54 2006 +0100&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Add git-blame, a tool for &lt;strong&gt;assigning blame.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I have also been working on a blame program. The algorithm is pretty&lt;br&gt;
much the one described by Junio in his blame.perl. My variant doesn't&lt;br&gt;
handle renames, but it shouldn't be too hard to add that. The output&lt;br&gt;
is minimal, just the line number followed by the commit SHA1...&lt;/em&gt;&lt;/p&gt;



&lt;p&gt;So here we go, git blame turns out to be described by its creator as &lt;strong&gt;a tool for assigning blame&lt;/strong&gt; and was originally unequivocally intended to do exactly what it says on the tin - assign blame. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Admittedly, the finding is no sensation - my detective work has led me to the outcome most would have rightfully assumed to be true by default, without feeling the need to go off and do hours of research on the topic in the hope of discovering that, surely, this was all down to a simple misunderstanding or innocent joke gone awry.&lt;/strong&gt;&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%2Frs2uglsk0dlv2xg9jyna.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%2Frs2uglsk0dlv2xg9jyna.png" alt="VScode extension blaming Fredrik"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, Fredrik was not the first one to have implemented a "blame" algorithm. As he says in his commit message, he was working off of Junio's &lt;a href="https://public-inbox.org/git/7vu0kiu8pm.fsf@assigned-by-dhcp.cox.net/" rel="noopener noreferrer"&gt;blame.perl&lt;/a&gt;, which makes copious use of the words blame and guilt itself, as shown below, in an excerpt from the blame algorithm's description.&lt;/p&gt;



&lt;p&gt;&lt;em&gt;How does this work, and what do we do about merges?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The algorithm considers that the first parent is our main line of development and treats it somewhat special than other parents.  So we &lt;strong&gt;pass on the blame&lt;/strong&gt; to the first parent if a line has not changed from it. For lines that have changed from the first parent, we must have either inherited that change from some other parent, or it could have been merge conflict resolution edit we did on our own.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The following picture illustrates how we pass on and &lt;strong&gt;assign blames.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the sample, the original O was forked into A and B and then merged into M.  Line 1, 2, and 4 did not change.  Line 3 and 5 are changed in A, and Line 5 and 6 are changed in B.  M made its own decision to resolve merge conflicts at Line 5 to something different from A and B:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+
+                A: 1 2 T 4 T 6
+               /               \ 
+O: 1 2 3 4 5 6                  M: 1 2 T 4 M S
+               \               / 
+                B: 1 2 3 4 S S
+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In the following picture, each line is annotated with a &lt;strong&gt;blame letter.&lt;/strong&gt;&lt;/em&gt; &lt;br&gt;
&lt;em&gt;A lowercase blame (e.g. "a" for "1") means that commit or its ancestor is &lt;strong&gt;the guilty party&lt;/strong&gt; but we do not know which particular ancestor is responsible for the change yet.  An &lt;strong&gt;uppercase blame&lt;/strong&gt; means that we know that commit is the &lt;strong&gt;guilty party&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Even I, self-appointed Language Police Officer™, can see nothing wrong with the above description. In the world of algorithms, removed from humans, the words "guilt" and "blame" are simply the most succinct descriptions of the variables' functionality. In this context, the drawbacks of their negative connotations don't outweigh their utility. &lt;/p&gt;

&lt;p&gt;But the rabbit hole goes even deeper than Junio's blame.perl. Turns out, another competing source control tool called Subversion had already &lt;a href="http://svnbook.red-bean.com/en/1.8/svn.ref.svn.c.blame.html" rel="noopener noreferrer"&gt;implemented a blame feature all the way back in 2003&lt;/a&gt;! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The usage of the term &lt;code&gt;blame&lt;/code&gt; is likely the result of 2 things: the word's variable naming utility and the collective mindset at the time.&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Contacting The Author 🗯️
&lt;/h2&gt;

&lt;p&gt;When I contacted the git feature's author, Fredrik Kuivinen, he told me that he mainly called it blame because it had been called blame &lt;a href="https://www.quora.com/Why-is-git-blame-called-blame?top_ans=62340411" rel="noopener noreferrer"&gt;elsewhere&lt;/a&gt; already. He also added the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;"In hindsight, I should have taken the opportunity to come up with a better name, e.g., "praise" which has been suggested by others."&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I felt vindicated. My temporary career change to detective had been worth it - after all, the author himself appears to agree a naming change would be beneficial! &lt;/p&gt;

&lt;p&gt;But at the time Fredrik was implementing the feature, coming up with a better name would have required an implausible amount of foresight on his part. Firstly, he would have had to anticipate the success of git and the future ubiquitousness of the feature. Secondly, he would have had to anticipate a cultural shift in tech. &lt;/p&gt;

&lt;p&gt;Moreover, the same command already existed elsewhere, and going with the default produces less friction than changing the status quo. And judging by mail exchanges, other contributors also preferred the naming of "blame" over "annotate".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Therefore, we will be assigning NO blame to Fredrik for implementing the feature in this article.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What have we learned? 🎓
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The term &lt;code&gt;blame&lt;/code&gt; in a version-control context existed elsewhere prior to git, because it is a succinct descriptor, and a reflection of the collective prevalent mindset at the time that no single individual is responsible for. &lt;/li&gt;
&lt;li&gt;Using words with negative affect in internal variables might in some cases well be the most elegant naming solution. But to, in 2021, name external commands in the same way, demonstrates either a lack of empathy for the end user or a lack of awareness of the significant impact language has on us all. &lt;/li&gt;
&lt;li&gt;Open source is magnificent. More work than I could have previously imagined went into git. I'm grateful for the hard work that continues to set the foundations of all technology that surrounds us. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  This doesn't seem like such a big deal, why get hung up on it? 💁🏼
&lt;/h2&gt;

&lt;p&gt;I agree that on an individual level, the existence of &lt;code&gt;git blame&lt;/code&gt; feels easy to brush off. Once the initial twinge of surprise at discovering the feature subsides, it's easy to go back to work and never question it again. But as I've explained above, the language we are exposed to continues to affect us in subtle but real ways. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So whilst the effect of &lt;code&gt;git blame&lt;/code&gt; on any one person might be negligible, its cumulative effect on an entire industry that encounters the feature every single day is significant. Over time, tiny amounts of shame and hesitation encountered by millions add up to a mountain of innovations foregone.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Moreover, many clearly still find it amusing that &lt;code&gt;git blame&lt;/code&gt; exists. To those who do, I'd say: get with the times, folks. Being a dick is 2000 and late. &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%2Fiwi9pq1qw9ec3gqt99o4.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%2Fiwi9pq1qw9ec3gqt99o4.png" alt="example of mindset that led to the criticised feature"&gt;&lt;/a&gt;&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%2F7i4ncdr1bxwppe9n8w91.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%2F7i4ncdr1bxwppe9n8w91.png" alt="example of mindset that led to the criticised feature"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And although I have no science to back this up, I have the suspicion that some are more affected by the feature than others. Those who engage in more introspection, those who feel they have more to lose if they commit the wrong code, those who experience a wider range of emotions overall. &lt;strong&gt;As we move towards creating a diverse workforce open to individuals from any background, we would do well to also adjust our language to be more inclusive, thus allowing anyone to feel welcome and contribute with confidence.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;So now, only one question remains... &lt;em&gt;who is confident in C and wants to submit a revolutionary patch to git?&lt;/em&gt; 🤩&lt;/p&gt;

</description>
      <category>git</category>
      <category>opensource</category>
      <category>github</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why You Should Learn Next Next</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Fri, 28 May 2021 16:25:32 +0000</pubDate>
      <link>https://dev.to/sanspanic/why-you-should-learn-next-next-5427</link>
      <guid>https://dev.to/sanspanic/why-you-should-learn-next-next-5427</guid>
      <description>&lt;p&gt;So you've learned React. You know, at least vaguely, what the virtual DOM is and are comfortable with using hooks including &lt;code&gt;useState&lt;/code&gt; , &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useRef&lt;/code&gt;. What is the logical &lt;strong&gt;next&lt;/strong&gt; step? I think you'll find the answer to this question within the question itself. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Next Episode
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/M62A05WrNTdEA/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/M62A05WrNTdEA/giphy.gif" alt="https://media.giphy.com/media/M62A05WrNTdEA/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next&lt;/strong&gt; is a framework built on top of React that purports to make the development process even more palatable. Personally, I enjoy working with React already, so I was surprised to find the extent to which Next delivers on its promise. &lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features
&lt;/h2&gt;

&lt;p&gt;What exactly makes learning Next a worthwhile endeavour? There's a lot that sets Next apart from simply using React, but let's start with 3 key features that Next implements to solve common React problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Server-Side Rendering (SSR)
&lt;/h2&gt;

&lt;p&gt;Upon inspecting the source code of a classic React application in the browser, you will notice that it doesn't contain much. Typically, the only html sent from the server is a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with the id of &lt;code&gt;root&lt;/code&gt;. The rest of the page gets rendered on the client side, i.e. inside the browser of the user. &lt;/p&gt;

&lt;p&gt;Of course, client-side rendering is what makes React powerful in the first place and enables it to utilise its virtual DOM, based on which the real DOM tree gets selectively updated. Instead of rewriting the entire DOM tree every time a change is made by a user, the virtual DOM is capable of selectively updating only those elements that are currently being manipulated.&lt;/p&gt;

&lt;p&gt;But React's biggest advantage can also be its biggest disadvantage in some specific cases. NextJS addresses these out-of-the-box, by default, whilst preserving React's other cool features. &lt;/p&gt;

&lt;h4&gt;
  
  
  Initial Load Time
&lt;/h4&gt;

&lt;p&gt;Loading the DOM in a React application can take some time, and depending on the internet speed of the user, this might result in a blank screen being displayed for longer than is optimal. &lt;/p&gt;

&lt;p&gt;SSR reduces the perceived load time of pages because the components are already pre-rendered into html pages on the server, as demonstrated in below video. Even though the actual time taken to load the contents of the DOM is similar, the non-SSR page on the left displays a blank page until all scripts are loaded, whereas the SSR page on the right appears to the user with instantaneously visible content. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Video demonstrating the difference in perceived page load times for non-SSR (left) and SSR (right). Network throttling enabled and set to ‘Regular 4G’ on Chrome Dev Tools. Credit: &lt;a href="https://medium.com/@swazza85/ssr-with-react-9cb197cfe380"&gt;S. Karavadi's excellent article.&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/225414319" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Data Fetching
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/O1xeZ4AgSaNBS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/O1xeZ4AgSaNBS/giphy.gif" alt="https://media.giphy.com/media/O1xeZ4AgSaNBS/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you're fetching data, because why wouldn't you be. After all, we're all just slaves to the data, much like dogs are slaves to the ball. A standard React application would need to load all its scripts first to realise it even contains a hook designed to fetch data. Only then would it be able to send a request for the data and wait for its response. &lt;/p&gt;

&lt;p&gt;We typically handle this by introducing spinners or similar components designed to tell the user the application is still waiting to receive its data. &lt;strong&gt;With Next, you are able to pre-fetch some data at build time, way ahead of the user's request to see it.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  SEO
&lt;/h4&gt;

&lt;p&gt;Although React already touts improved SEO capabilities compared to standard Javascript-heavy web apps, Next elevates these to the &lt;strong&gt;next&lt;/strong&gt; level. In standard React applications, search engine crawlers will typically only see the initially empty html page being sent from the server. Pre-rendering your pages on the server side addresses this potential hiccup and &lt;strong&gt;allows search engine crawlers to see the content of the application&lt;/strong&gt; and consequently to be able to index it properly. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Simplified Routing
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/rDroB384ydCvK/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/rDroB384ydCvK/giphy.gif" alt="https://media.giphy.com/media/rDroB384ydCvK/giphy.gif"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Say goodbye to React-Router-DOM and its ever-changing documentation (&lt;em&gt;although, I do appreciate you, maintainers!).&lt;/em&gt; Say hello to defining pages and routes within your folder structure instead! Next comes with a folder called pages, which you can fill with... well, pages. &lt;strong&gt;Each file inside the pages folder willl automatically convert to an eponymous route.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/pages 
    /about.js
    /index.js
    /projects.js
    /writing.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above folder structure would translate to an application that has the following routes: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/index.js&lt;/code&gt;  - BASEURL/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/about.js&lt;/code&gt; - BASEURL/about/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/projects.js&lt;/code&gt; - BASEURL/projects/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/writing.js&lt;/code&gt; - BASEURL/writing/&lt;/p&gt;

&lt;p&gt;Neat, right? The file &lt;code&gt;index.js&lt;/code&gt; maps directly onto the route &lt;code&gt;/&lt;/code&gt; by default. Next can also easily handle nested routes, like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/pages 
    /index.js
    /snoop
        /dogg.js
        /doggydogg.js
        /index.js
        /lion.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above folder structure would translate to an application with the following routes: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/index.js&lt;/code&gt; - BASEURL/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/snoop/index.js&lt;/code&gt; - BASEURL/snoop/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/snoop/dogg.js&lt;/code&gt; - BASEURL/snoop/dogg/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/snoop/doggydogg.js&lt;/code&gt; - BASEURL/snoop/doggydogg/&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/snoop/lion.js&lt;/code&gt; - BASEURL/snoop/lion/&lt;/p&gt;

&lt;p&gt;What about dynamic routes with dynamic parameters? Not a problem for Next either.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="sr"&gt;/page&lt;/span&gt;&lt;span class="err"&gt;s
&lt;/span&gt;    &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
    &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;about&lt;/span&gt;
    &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;
        &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
        &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By wrapping a file name in square brackets, you can indicate to Next that you're defining a dynamic route, the parameter of which you can then access from within your code. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;/pages/products/[productId]&lt;/code&gt; - BASEURL/products/{param}/&lt;/p&gt;

&lt;p&gt;I'll go into more detail about how to access dynamic parameters in an article that focuses specifically on routing. But for the purposes of this article, just let it be known that handling routing is pretty intuitive and doesn't involve importing any additional libraries. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Backend Capabilities
&lt;/h2&gt;

&lt;p&gt;NextJS also enables us to incorporate backend code that, say, communicates with a database or with the filesystem. You might find yourself writing NodeJS code inside a Next application to perform CRUD operations or authenticate users. The benefit of building a full-stack application using Next is that you no longer have to switch between separate projects to fine-tune your application. &lt;/p&gt;

&lt;p&gt;Files that live inside the folder &lt;code&gt;pages/api&lt;/code&gt;, which is created by default, will be treated as API endpoints. For instance, a route resulting from the file-path &lt;code&gt;pages/api/artist.js&lt;/code&gt; would return a JSON response with a status code of 200, if it had something akin to the following backend code in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;json&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="s1"&gt;Snoop Doggy Dogg&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;I initially had no idea Next was capable of this. Knowing that I can create RESTful APIs using a React framework that I intuitively only associated with frontend capabilities continues to blow my mind. &lt;/p&gt;

&lt;h2&gt;
  
  
  That's It?
&lt;/h2&gt;

&lt;p&gt;Nope, I barely scratched the surface. I found a very concise but technical summary of cool Next features on &lt;a href="https://www.reddit.com/r/reactjs/comments/au5z1u/does_nextjs_will_be_soon_obsolete/"&gt;Reddit&lt;/a&gt; by none other than the (then) lead maintainer of Next. I encourage you to read it if you want to know more but can't be bothered actually spending hours sifting through the sizeable official Next documentation (which itself, by the way, ticks all "great docs" boxes in my opinion). &lt;/p&gt;

&lt;h2&gt;
  
  
  Still Not Convinced?
&lt;/h2&gt;

&lt;p&gt;Another consideration is that NextJS is not just some fad that will blow over in a couple of months. Initially released by Vercel in 2016, it's become a well-established framework with an ever-growing community of users, making it a sought-after skill in the job market. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NextJS is here to stay, and slay.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arguably, NextJS is already famous enough to render this article pretty much pointless. &lt;em&gt;One last proof of Next's supreme rendering capabilities.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1gUWdf8Z8HCxpM8cUR/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1gUWdf8Z8HCxpM8cUR/giphy.gif" alt="https://media.giphy.com/media/1gUWdf8Z8HCxpM8cUR/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
      <category>node</category>
    </item>
    <item>
      <title>How to Ace the Behavioural Interview</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Tue, 11 May 2021 18:42:34 +0000</pubDate>
      <link>https://dev.to/sanspanic/how-to-ace-the-behavioural-interview-15g1</link>
      <guid>https://dev.to/sanspanic/how-to-ace-the-behavioural-interview-15g1</guid>
      <description>&lt;p&gt;As you might have already guessed, this article is not about technical interviews, coding challenges, let alone about (&lt;em&gt;shudders&lt;/em&gt;) algorithms. I'm not qualified to give anyone advice on above, but having transitioned to tech from mental health, I do know a thing or two about human behaviour. By extension, I'm declaring myself qualified to dish out advice on behavioural interviews. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This article is about all aspects of the interview process that are NOT strictly coding-related, and will be particularly useful to those who are transitioning careers to tech from a different industry.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's go! 🤸‍♀️&lt;/p&gt;

&lt;h3&gt;
  
  
  The Tech Recruitment Process 🧭
&lt;/h3&gt;

&lt;p&gt;Typically, interviews in the tech industry have at least 4 rounds, although of course the exact schedule will vary from company to company.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Application/Recruiter Email&lt;/li&gt;
&lt;li&gt;The Recruiter Screening Call &lt;/li&gt;
&lt;li&gt;The Technical Interview/The Takeaway Coding Challenge&lt;/li&gt;
&lt;li&gt;The Behavioural Interview&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Rounds 1, 2 and 4 all have to do with who you are as a person, as much as they have to do with your skills. There is a 100% likelihood you will have to tell your interviewers about yourself and your background, and unless you come across as someone your interviewers would enjoy working with, no amount of skills will help you land your dream role. It's not easy to get an offer, especially if you're switching careers from a different industry, so being prepared to talk about yourself eloquently might well be what distinguishes you from your competition. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/XtB0qy4kx8jCM/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/XtB0qy4kx8jCM/giphy.gif" alt="https://media.giphy.com/media/XtB0qy4kx8jCM/giphy.gif" width="500" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Interviewing Well is a Skill. ⌛
&lt;/h2&gt;

&lt;p&gt;The good news is that interviewing, just like any other skill, is one you can improve with practice. It certainly took me a lot of practice to sound confident and convincing in interview situations - I'm still not amazing at it. The last in-person interview I went to pre-career-switch to tech ended in tears - not only did I come across as an idiot, I also knocked over a glass of water onto the interviewer sat across me. &lt;/p&gt;

&lt;p&gt;Why was it such a nightmare? Because I hated the sound of the job, and, as a result, was woefully underprepared to talk about myself and my motivation for applying to it. &lt;em&gt;Why did you apply for it, if you hated the sound of it&lt;/em&gt;, I hear you ask? &lt;em&gt;Excellent&lt;/em&gt; &lt;em&gt;question. I had no idea what I was doing with my life&lt;/em&gt;, I hear myself answer. &lt;/p&gt;

&lt;p&gt;This brings me to my first piece of advice, which I'll kick the useful part of this article off with. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. Make Sure You Like What You're Applying To. 💫
&lt;/h3&gt;

&lt;p&gt;If you don't show enthusiasm for the role or find yourself having to fake it, your interviewers will sense this and offer the role to a more motivated candidate. If you hate the way social media has contributed to the polarisation of society, try not to apply for a job at Facebook, unless you believe you can fix it (&lt;em&gt;please... someone fix it. anyone..?&lt;/em&gt; ). If the sound of working for a local start-up that creates a productivity management tool sounds boring beyond belief to you, manage your own productivity better by saving yourself the hassle of an application. &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Ten Applications A Day Keep the Salary At Bay. 👩‍💻
&lt;/h3&gt;

&lt;p&gt;I see a lot of well-intentioned advice encouraging candidates to apply to ten positions a day. In my potentially controversial opinion, this is complete nonsense. In the best case scenario, you'll hear back from numerous companies, which will mean that you're now involved in too many recruitment processes at once. This won't give you enough time to do your due diligence and bring your best self to each interview. In the worst case scenario, you've spread yourself too thin and given each application so little thought that you barely hear back from anyone. I'd recommend you go for quality instead of quantity. One or two applications per day are plenty, especially if you're tailoring your CVs and cover letters uniquely to each position you apply to. Which is something you should really be doing! &lt;/p&gt;

&lt;h3&gt;
  
  
  3. Prepare Answers to Common Questions in Advance. 📝
&lt;/h3&gt;

&lt;p&gt;The chance of you not hearing the following words from an interviewer at some point during the process is precisely zero: &lt;strong&gt;so, could you please tell us a bit about yourself&lt;/strong&gt;... Knowing this gives you the power to absolutely ace this question. Below is a list of other guaranteed questions you might want to prepare for. The list should be particularly relevant to those who are transitioning careers, i.e. the target audience of this article. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tell us a bit about yourself.&lt;/li&gt;
&lt;li&gt;What prompted you to start coding? &lt;/li&gt;
&lt;li&gt;What do you particularly like about front-end/back-end/data science/whatever-the-job-is? &lt;/li&gt;
&lt;li&gt;Tell me about a time in your life when you successfully worked as part of a team.&lt;/li&gt;
&lt;li&gt;Tell me about a time in your life when you successfully dealt with a challenging situation. &lt;/li&gt;
&lt;li&gt;What made you apply to this particular position, in our particular company? &lt;/li&gt;
&lt;li&gt;What are your favourite coding-related resources? &lt;/li&gt;
&lt;li&gt;Do you have any questions for us? &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;I can pretty much guarantee that most of above questions, or some permutations thereof, will be asked.&lt;/strong&gt; There is no reason you should have to think about these on the spot and struggle with a coherent reply. Take your time to think about these questions beforehand, and write your answers out. Read them, tweak them for maximum impact, commit them to memory. &lt;/p&gt;

&lt;p&gt;Every interview is slightly different so you will still get ample space to improvise, but &lt;strong&gt;pre-empting as many questions as you can will make you a better candidate&lt;/strong&gt;. This seems like extremely obvious advice, but many still don't follow it - make sure you slot yourself into the category of those who do to capitalise on this opportunity. I'd argue that preparing replies to commonly asked questions is &lt;strong&gt;the one easiest and most impactful step&lt;/strong&gt; any candidate can take to stand out.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Talk to Yourself. Out Loud. Seriously. 📢
&lt;/h3&gt;

&lt;p&gt;When preparing for your interview, don't do it in silence. Practice your replies out loud to get more familiar with how you want to convey your points. &lt;strong&gt;Interviews are by default a performative action, and like every performance, the more you do it, the better you get at it&lt;/strong&gt;. Some even go as far as to advise candidates to record themselves and analyse how they come across - I'd say that's a step too far, but there's nothing wrong with standing in front of a mirror (or a willing other) and rattling your script down until you're happy with your "act". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o7aD0QILFVJQEOb2E/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o7aD0QILFVJQEOb2E/giphy.gif" alt="https://media.giphy.com/media/3o7aD0QILFVJQEOb2E/giphy.gif" width="342" height="252"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Do Some Detective Work. 🔎
&lt;/h3&gt;

&lt;p&gt;In this situation only, being a stalker is a perfectly acceptable way to be. Researching your interview panel is useful for two reasons. Firstly, you might get a better idea of what life at the company you're applying to is like, and what your job might entail. Having this knowledge will help you craft better answers during the interview.  You might even pick up an impressive tidbit of information that you can impress the panel with during your interview. Secondly, you might get a better sense of the type of person the company hires. If you see any red flags here, run. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3ohc0Rnm6JE0cg0RvG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3ohc0Rnm6JE0cg0RvG/giphy.gif" alt="https://media.giphy.com/media/3ohc0Rnm6JE0cg0RvG/giphy.gif" width="400" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Leverage Your Non-Tech Background. ✨
&lt;/h3&gt;

&lt;p&gt;No CS degree? No problem! Whatever it is you've been doing with your life, you must have learned a thing or two. The trick is to tailor your story towards the job you want and make your diverse background sound like a benefit, rather than a drawback of hiring you. &lt;/p&gt;

&lt;p&gt;Did you work in hospitality before? You must know how to deal with people and be able to spontaneously improvise solutions to tricky situations really effectively! Were you in customer service? Your communication skills must be off the charts. Were you an athlete or a musician? Wow, I bet you have tons of discipline and will code us all under the table in a couple of years. Did you spend a few years traveling? How resourceful and adaptive that must make you! Are you perhaps a parent? You win by default, you literally created a human being. You must be incredibly organised and excellent at time management to juggle all that AND change your career. &lt;/p&gt;

&lt;p&gt;Soft skills are important in any environment, and software engineering is no exception. Make your background work for you! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/l0ExghDSRxU2g55sc/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l0ExghDSRxU2g55sc/giphy.gif" alt="https://media.giphy.com/media/l0ExghDSRxU2g55sc/giphy.gif" width="480" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Bring Your Whole Self. ⭐
&lt;/h3&gt;

&lt;p&gt;Don't hide your personality - display it proudly! &lt;em&gt;Unless your personality sucks, in which case, definitely hide your personality&lt;/em&gt;. But seriously, your future employers are interested in who you are as a person as much as they are interested in your skills. You won't exist in a vacuum, on the contrary, you will constantly be interacting with others and contributing to a team, so being a person who's easy to get on with will go a long way. &lt;/p&gt;

&lt;p&gt;You don't have to rely on solely professional examples to illustrate who you are - you are way more than just your previous jobs or studies. Feel free to draw on other areas of your life for examples of what makes you uniquely you. For example, I have a thing for acrobatics and enjoy balancing people on my shoulders. During my interview, I used the example of acrobatics to illustrate my approach to teamwork - in acrobatics, communication is just as important as skill and no human pyramid would ever go up would the entire team not be on the same page regarding effective communication. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/SGsdST7lHYafsTQ1j4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/SGsdST7lHYafsTQ1j4/giphy.gif" alt="https://media.giphy.com/media/SGsdST7lHYafsTQ1j4/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8. The Fear Won't Persevere. 🙀
&lt;/h3&gt;

&lt;p&gt;There is an aspect of interviewing that is unique to the interview itself and cannot be replicated during solo practice in front of a mirror -  I mean the nerve-wracking, anxiety-inducing, "this-is-a-live-situation-and-I-only-have-one-chance" part of it all. I don't know about you, but I'm pretty much shaking before any interview. Even if on the surface I look calm and ready, you're likely to find vomit on my sweater already - mom's spaghetti. (&lt;em&gt;I really hope this is a reference people get. I'm not that weird, I promise.&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Jokes aside, some adrenaline is helpful and leads you to think clearer, but too much of it can muddle your thoughts. I've found it helpful to internally reframe The Fear™  as simply Extreme Excitement™. &lt;em&gt;I'm not dreading this and shaking out of fear, I just can't wait to seize this opportunity, that's all!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This, too, is a practicable skill. Even if you tend to get very unsettled by interviews at the moment, it doesn't mean you always will. The more interview processes you go through, the more practice you get with regulating your interview feelings, meaning you will interview better in the future. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/xT0xey2FaDj3GQmFs4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/xT0xey2FaDj3GQmFs4/giphy.gif" alt="https://media.giphy.com/media/xT0xey2FaDj3GQmFs4/giphy.gif" width="480" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Normalise Rejection. ❤️‍🩹
&lt;/h3&gt;

&lt;p&gt;If you get rejected, you're just one interview closer to the interview that will result in a job offer. I know, this is easier said than done. But try to bear in mind that you're not alone. The struggle is real for all of us. Rejection is tough, but completely normal - just another day at the office, even for experienced developers. But equally importantly, don't beat yourself up over feeling down. We all have different emotional spans, and being someone who takes rejection to heart more significantly than others does not make you a worse (or better) candidate. Your feelings are valid, so accept them and let yourself experience them fully, prior to moving on. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/12EFa8Vc5kVlOU/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/12EFa8Vc5kVlOU/giphy.gif" alt="https://media.giphy.com/media/12EFa8Vc5kVlOU/giphy.gif" width="500" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Always Ask For Feedback. 🙋
&lt;/h3&gt;

&lt;p&gt;If you've spent weeks of your life interviewing for a company and made it all the way through to the behavioural interview, the least the company can do after deciding to offer the job to someone else is provide you with useful feedback. &lt;strong&gt;If they don't do this, it means you likely dodged a bullet anyways&lt;/strong&gt;. Frequently, the feedback you will receive will be useful and inform your next attempt. Other times, the feedback will be that you were &lt;strong&gt;this&lt;/strong&gt; close to getting an offer, but someone else with the slightest bit of more directly relevant experience was in the end deemed a better choice. Whilst this type of feedback is not super useful, it should hopefully serve to raise your spirits and reassure you that you're very, very close. Either way, asking for feedback can only result in positive outcomes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3otPoScZw3enH8ZGKY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3otPoScZw3enH8ZGKY/giphy.gif" alt="https://media.giphy.com/media/3otPoScZw3enH8ZGKY/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  11. Don't Lie. 🤥
&lt;/h3&gt;

&lt;p&gt;Last but not least, be honest - with yourself and with your interviewers. Pretending you are really into animations, when in reality you've barely ever encountered an SVG before, is unnecessary. At best, you might get offered the job and realise you've sold yourself as an expert when in reality you have no idea what you're doing, in which case you'll be found out immediately. At worst, faking expertise might lead to you coming across as cocky and never getting offered the job in the first place. &lt;/p&gt;

&lt;p&gt;Nobody, I repeat, NOBODY, is an expert at everything. Senior devs get better at knowing exactly what it is they don't know, which makes it easier to ask the right questions and seek out answers in the right places. But even seniors would be lying if they claimed they're the absolute bee's knees at every single topic. If you're only just starting your tech career, it's much wiser to openly admit your technical gaps and frame them as areas of growth you are aware of and excited to explore.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/Q9kgQp6ptfcLS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Q9kgQp6ptfcLS/giphy.gif" alt="https://media.giphy.com/media/Q9kgQp6ptfcLS/giphy.gif" width="500" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Still with me?
&lt;/h3&gt;

&lt;p&gt;Wow, you must really want that job. Now go get it! 🎉🎉 &lt;/p&gt;

&lt;p&gt;Let me know if I missed out on any techniques you might be aware of in the comments, and feel free to connect with me on &lt;a href="https://twitter.com/sansPanicDev"&gt;Twitter&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/sandra-spanikova-6738aa1b7/"&gt;LinkedIn&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>career</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Coding Advice I Wish I'd Trusted Earlier</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Thu, 22 Apr 2021 14:03:37 +0000</pubDate>
      <link>https://dev.to/sanspanic/coding-advice-i-wish-i-d-trusted-earlier-f1f</link>
      <guid>https://dev.to/sanspanic/coding-advice-i-wish-i-d-trusted-earlier-f1f</guid>
      <description>&lt;p&gt;I've recently celebrated my 1 year anniversary of picking up coding. A lot has changed in the past year, and I've been fortunate enough to recently get hired by a tech company for my very first software engineering role.&lt;/p&gt;

&lt;p&gt;I know, I know... There's a plethora of advice articles like these out there, as was the case a year ago. &lt;strong&gt;Despite having read many myself when I was starting out, I remember being dismissive of some their advice, especially in cases where it was misaligned with my pre-existing intuitions.&lt;/strong&gt; &lt;em&gt;Umm, how about I ignore 24 different articles I've read that advise me to do a thing and instead proceed NOT to do it, thanksss.&lt;/em&gt; 💅 &lt;/p&gt;

&lt;p&gt;For example, having an online presence seemed a yucky and unnecessary waste of time. I'm now glad I re-examined my stance, because I was approached for my current position by a recruiter on LinkedIn. This wouldn't have happened, had I stubbornly clung to my notion that I can do this my own way without resorting to what I at the time considered to be nauseating concepts such as digital self-marketing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, in full acknowledgement that the body of literature is already vast, I'll add another voice "from the other side", in the hope that I might convince someone as stubborn as I was to give the below advice some consideration.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Without further ado, here's the advice I'd give my younger self as well as anyone else starting on their coding journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Consider Whether a Bootcamp is Right for You 🗺️
&lt;/h2&gt;

&lt;p&gt;Do you need to attend a bootcamp in order to learn to code? Absolutely not. Are all the resources you need to learn to code available online for free? Absolutely yes. So, will you still benefit from completing a bootcamp? 🤔 Also yes! &lt;strong&gt;A curriculum designed by expert teachers will make it easier to learn things in the right order and avoid diving into topics that require pre-existing knowledge.&lt;/strong&gt; For example, you should really start by learning vanilla JavaScript and regular DOM manipulation before exploring React. Otherwise, your mental model of how the frontend works will be lacking. &lt;/p&gt;

&lt;p&gt;But bootcamps are a GIANT commitment. &lt;strong&gt;Before you dish out money and scale back other responsibilities to make time for what is a very intense experience - please make sure you actually like coding.&lt;/strong&gt; This might seem self-explanatory, but there is a surprising amount of students who invest money and time prior to making sure they have a long-term interest in the subject. &lt;/p&gt;

&lt;p&gt;Thankfully, a lot of cheap Udemy or free Youtube tutorials exist to help with this. &lt;strong&gt;Having a solid mental model of a programming language will set you up for success and make it easier to keep up with a bootcamp's fast pace.&lt;/strong&gt; I started with &lt;a href="https://www.udemy.com/course/the-modern-python3-bootcamp/" rel="noopener noreferrer"&gt;Colt Steele's Udemy Modern Python Bootcamp&lt;/a&gt;, then continued with his &lt;a href="https://www.udemy.com/course/the-web-developer-bootcamp/" rel="noopener noreferrer"&gt;Web Development Bootcamp&lt;/a&gt; before enrolling in an actual bootcamp. I could go on about what an excellent teacher with equally excellent pet-naming conventions Colt is (&lt;em&gt;his chicken is called Stevie Chicks, guys, need I say more&lt;/em&gt;), but I'd only sound like a silly fan-girl. Instead, I will leave you with the names of some equally great instructors who also offer high-quality free or cheap courses: &lt;a href="https://www.udemy.com/course/100-days-of-code/" rel="noopener noreferrer"&gt;Angela Yu&lt;/a&gt;, &lt;a href="https://www.udemy.com/course/the-complete-web-developer-zero-to-mastery/" rel="noopener noreferrer"&gt;Andrei Neagoie&lt;/a&gt;, &lt;a href="https://www.udemy.com/course/python-for-data-science-and-machine-learning-bootcamp/" rel="noopener noreferrer"&gt;Jose Portilla&lt;/a&gt;, but the list goes on. &lt;/p&gt;

&lt;p&gt;2020 might have brought a pandemic, Zoom meetings and Cyberpunk 2077, but it has also graced us with an ever-increasing amount of online content creators putting out accessible courses. Take your pick! &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Choose the Right Bootcamp 💻
&lt;/h2&gt;

&lt;p&gt;If you are going down the bootcamp route (and your success doesn't by any means hinge on this, there are other ways), a word of warning: &lt;strong&gt;choose your bootcamp carefully&lt;/strong&gt;. I could write a whole article on solid criteria to judge a bootcamp by (&lt;em&gt;should I? Let me know in the comments&lt;/em&gt;), but ultimately, some of these will be subjective. Different teaching styles and curriculums suit different circumstances and learning styles. &lt;strong&gt;Personally, I was glad to have steered clear of bootcamps that either don't have an entry exam, or have an extremely easy one&lt;/strong&gt; (e.g. "write a function that returns the sum of 2 numbers", or "return the first item in this array"). Bootcamps typically last anywhere between 3 to 9 months, and I am mistrustful of curriculums that promise to teach you all you need to know in a junior role within this time period without requiring any pre-requisites on your part. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I'm also sceptical of bootcamps that teach more than 2 languages&lt;/strong&gt; - you might end up replacing depth of understanding with breadth and leave the bootcamp not feeling confident you can actually fully utilise the tools you now list on your CV. A good way to judge the quality of a bootcamp is to find graduates and look at their projects or portfolio sites - you might need to do some LinkedIn, Github or Twitter stalking to gather a large enough sample size to conclusively determine a bootcamp's quality. Connecting with and speaking with ex-students is also a great idea. &lt;/p&gt;

&lt;p&gt;Lastly, check out &lt;a href="https://www.switchup.org/" rel="noopener noreferrer"&gt;SwitchUp&lt;/a&gt; and &lt;a href="https://www.coursereport.com/" rel="noopener noreferrer"&gt;Coursereport&lt;/a&gt; for rankings and reviews. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create a LinkedIn Profile - Early 👔
&lt;/h2&gt;

&lt;p&gt;Whether you've chosen to do a bootcamp or are a brave self-learner, &lt;strong&gt;do not underestimate the power of networking&lt;/strong&gt;. This one was the toughest piece of advice for me to digest, and I kept putting off creating a LinkedIn profile until my bootcamp's career service basically forced me to. For many of us, networking feels icky, digital self-promotion is a nauseating concept, and creating a LinkedIn profile feels akin to selling our soul to the devil. I, too, felt this way, and to a certain degree still do - I don't like living in a world which incentivises us shouting about our achievements from the top of our lungs and essentially marketing ourselves as products. &lt;/p&gt;

&lt;p&gt;But LinkedIn also got me a job and connected me with many seriously impressive people. There's no two ways about it - &lt;strong&gt;if you're trying to break into tech via an unconventional route, you will benefit from having a LinkedIn account&lt;/strong&gt;. Make sure your bio is well-written, concise and that you list any previous experience you might have, regardless of whether or not it is tech-related. The idea is that by the time you are ready for a job, you will already have a network of contacts and a history of consistently demonstrating your tech capabilities online, be it via deployed applications, posts or articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Write About Your Learning - Early 🖋️
&lt;/h2&gt;

&lt;p&gt;This was another oft-repeated piece of advice I was initially sceptical about. &lt;em&gt;What could I possibly contribute to the body of coding literature that hasn't already been said, by people a million times more qualified than me, a lowly degree-less peasant?&lt;/em&gt; I started writing articles about my learning relatively late, once I had already moved on from most backend topics. So from the outside, my online presence seems focused exclusively on frontend, and I had to convince my future full-stack role employer that I was equally, if not more, interested in backend. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If I could do it all again, I would definitely start writing way earlier.&lt;/strong&gt; If you're put off by the fact that you don't know much yet and might make mistakes - don't be. No matter what you write about, chances are, someone out there will read your content and find it informative. More importantly, by writing about topics you're not expert on, you (hopefully) end up researching them more in-depth than you would otherwise. &lt;/p&gt;

&lt;p&gt;Plus, if you make a mistake, people will let you know in the comments, and you'll have the opportunity to correct your mistake and learn. I cannot stress enough how helpful it is to write stuff out - I really wish I had started earlier, and my aim will be to continue writing, even as I transition into a full-time role, because &lt;strong&gt;I now know that it's an excellent way to solidify new knowledge.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Learn Version Control - Early(ish) 📁
&lt;/h2&gt;

&lt;p&gt;Having a history of committing your code on Github is the easiest way to demonstrate your skills to recruiters. At some point, you will want to start uploading the exercises you complete to Github. Even though I started coding in April 2020, I didn't upload much to Github until November 2020, which is when my bootcamp started encouraging me to do so. What a waste, by then I had created a fair few full-stack applications that the world will never get to see! (&lt;em&gt;They're terrible. The world lucked out.&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;I should have started earlier, perhaps 2 months in. &lt;strong&gt;Learning Git can be confusing at first, so I would wait until I have a basic understanding of a programming language in order not to overwhelm myself.&lt;/strong&gt; But a couple of months in, Git becomes a necessity. Once again, &lt;a href="https://www.youtube.com/results?search_query=learn+git" rel="noopener noreferrer"&gt;Youtube&lt;/a&gt; comes to the rescue. &lt;/p&gt;

&lt;h2&gt;
  
  
  6. Focus Your Energy Where It Matters ⏱️
&lt;/h2&gt;

&lt;p&gt;If you're not just coding for the fun of it, but also aim to transition into the industry professionally, &lt;strong&gt;consider scaling back as many other commitments as you are able to&lt;/strong&gt;. I'm aware this won't always be possible, for example, if you're a parent or relying on income from a full-time job (&lt;em&gt;in which case you're an absolute trooper and my admiration for you doing all that AND re-skilling has no bounds&lt;/em&gt;). In my experience, there will come a time when you will start feeling compelled to make some tough decision about whether or not to give up other areas in your life to focus more on coding. &lt;/p&gt;

&lt;p&gt;In my case, half-way through my (remote-first) bootcamp, I had to give up not one, but two part-time gigs that were keeping me afloat and rely on government assistance instead. It felt risky, and I also felt like I was letting people down by leaving my roles, but it has proved to be the right long-term move and I am proud of myself for having let go at the right time. It's a tough thing to do. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As with any skill, the more time and energy you spend on learning it, the better.&lt;/strong&gt; It's a bit of a no-brainer, really. The difficult part is recognising, in real time, what truly matters and what can be filtered out. I hope it helps to know that if you're struggling to meet all your commitments alongside learning to code - you're not alone, many of us have been in a similar situation. &lt;strong&gt;There's no shame in letting go of jobs, hobbies or relationships that eat up our time and energy without giving much in return.&lt;/strong&gt; In fact, it's a brave thing to do. &lt;/p&gt;

&lt;h2&gt;
  
  
  7. Taking Breaks is Key 💤
&lt;/h2&gt;

&lt;p&gt;Having said this, increasing coding time doesn't always proportionally translate into more success - there is a limit, in my experience, to how much brain power one should devote to coding per day. This might vary on a case-by-case basis, but for me, this meant disengaging in the evenings and taking weekends off. We all operate optimally at different times of the day, so by all means follow your own circadian rhythm, but bear in mind that an overworked brain rarely produces good code. &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%2Fmhi6fyoa2chcv5ys3mob.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%2Fmhi6fyoa2chcv5ys3mob.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, I take my breaks very seriously. I took Christmas off, and I barely ever code on weekends. &lt;strong&gt;This strategy will hopefully help me, in the long-run, prevent burnout and help me retain my child-like fascination for writing code.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;What I was initially terrible at is knowing when to stop. There were days when I kept staring into my screen, frantically fixing fearsome bugs at night-time, after already having worked since the morning. Reliably, I'd fix a bug I was stuck on for many evening hours the previous day within the first 30 minutes in the morning. Equally reliably, next time, I'd tell myself that &lt;em&gt;this time is different&lt;/em&gt; and &lt;em&gt;this time I'll fix the bug in the evening, if I only spend 10 more minutes on it&lt;/em&gt;. &lt;strong&gt;Giving up and calling it a day was a difficult skill to learn - one that I am still perfecting.&lt;/strong&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  8. Mindset Matters More Than You Might Think 🧠
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;You can learn anything, if you only believe it.&lt;/strong&gt; This is not a vapid platitude, but our actual current scientific understanding of &lt;a href="https://www.verywellmind.com/what-is-brain-plasticity-2794886" rel="noopener noreferrer"&gt;neuroplasticity&lt;/a&gt;. Each time you learn, your brain forms, strengthens or rearranges neural pathways. This means you have the power to actively and purposefully shape the physical outline of your brain - &lt;em&gt;how cool is that&lt;/em&gt;. The belief that people can't change is not only archaic and wrong, it is also dangerous and leads individuals to accept malleable traits and skills as unchangeable constants. &lt;/p&gt;

&lt;p&gt;There is a slight snag though - in order to learn best, it is beneficial to adopt the belief that you &lt;strong&gt;CAN&lt;/strong&gt;, indeed, learn. Dismantle limiting beliefs such as "&lt;em&gt;coding is similar to Maths and I'm just not a Maths person&lt;/em&gt;" or "&lt;em&gt;I will never be expert at coding because I started too late in life&lt;/em&gt;", and you will have a better time learning. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intelligence is not set at birth.&lt;/strong&gt; Trust me, I wrote a dissertation in Psychology. Or don't, because let's face it, writing a dissertation in something years ago doesn't make you an expert. But do trust current academics. While there is an ongoing debate about the extent to which our genes predetermine our cognitive ability, the fact that any individual can greatly shape their intelligence is no longer disputed - not even a little. Having the belief that intelligence is not fixed but can instead be developed through our own efforts is also referred to as the &lt;a href="https://www.psychologytoday.com/gb/blog/click-here-happiness/201904/15-ways-build-growth-mindset" rel="noopener noreferrer"&gt;&lt;strong&gt;growth-mindset&lt;/strong&gt;&lt;/a&gt;. That's the mindset you want to apply to coding as well. &lt;/p&gt;

&lt;h2&gt;
  
  
  9. No, Programming is Not Easy, And That's Great 🏃‍♀️
&lt;/h2&gt;

&lt;p&gt;Another beneficial expectation to keep in mind is that programming is hard. &lt;strong&gt;Don't expect it to be otherwise.&lt;/strong&gt; It's really not easy to pick up coding from scratch, especially for someone who has never done anything like it before. It's a completely new way of thinking, and the ability to reason effectively about abstract concepts takes a while to develop. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't get discouraged by this fact - it's completely normal to struggle and to need to revisit concepts you thought you already mastered over and over again.&lt;/strong&gt; With time, you will get better at asking the right questions and knowing exactly what it is you don't know, but don't ever expect yourself to know all the answers off the top of your head. &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%2F37i6vbcu3t7fmrxz92h1.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%2F37i6vbcu3t7fmrxz92h1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Let's Normalise Tears 💧
&lt;/h2&gt;

&lt;p&gt;This final piece of advice is intended for me as much as it is intended for you. &lt;strong&gt;It's okay to feel things as you code&lt;/strong&gt;, especially as you encounter challenging situations - of which there will be many. It's okay to feel joyous at successfully deploying an app, and it's equally okay to feel sad when CORS strikes again and things don't work. &lt;/p&gt;

&lt;p&gt;Different people have different emotional spans. For cultural and, frankly, sexist reasons, the industry has typically attracted a certain type of person. You wouldn't normally associate this type of person with displaying a wide array of emotions. (&lt;em&gt;An oversimplified generalisation, but it will do for the purposes of this article&lt;/em&gt;). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nowadays, things are changing, and as a more diverse workforce enters the industry, I hope we gradually normalise feelings in a software engineering context.&lt;/strong&gt; I, for one, feel things intensely on either end of the emotional spectrum, and I want to rid myself of the notion that displaying either positive or negative feelings is in some way &lt;em&gt;shameful&lt;/em&gt;, or a sign of weakness. On the contrary, bringing feelings and empathy to a coding context is a bonus, because after all, the people using our software are just that - &lt;strong&gt;people&lt;/strong&gt;, and being able to put ourselves in their shoes can only enhance a product. &lt;/p&gt;

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

&lt;p&gt;I hope you will find the above advice useful. I recognise that we're all unique individuals, and as such our "best coding practices" might vary. What worked for me might not necessarily work for you. If, for example, you're the kind of person that doesn't mind working long hours and weekends, you might be able to get where I am now in half the time. But on average, I believe above advice to be general enough to apply to a large proportion of people reading this. &lt;/p&gt;

&lt;p&gt;Thanks for reading, and happy coding! &lt;em&gt;Or sad coding, for that matter. Your feelings are valid, whatever they might be.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Just know that you've got this! ✨💪
&lt;/h2&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>My Coding Journey - Becoming A Software Engineer in Under 1 Year</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Wed, 14 Apr 2021 16:15:20 +0000</pubDate>
      <link>https://dev.to/sanspanic/my-coding-journey-becoming-a-software-engineer-in-under-1-year-12de</link>
      <guid>https://dev.to/sanspanic/my-coding-journey-becoming-a-software-engineer-in-under-1-year-12de</guid>
      <description>&lt;p&gt;&lt;em&gt;I've written my first line of code exactly one year ago. Today, I'm preparing to start my new job as software engineer. Here's my story.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🌪️ The Interview to End All Interviews 🌪️
&lt;/h3&gt;

&lt;p&gt;In February 2020, I ran out of an interview room with tears streaming down my face. I was interviewing for yet another administrative role at an educational institution I had precisely zero desire to actually do. The first part of the interview consisted of an Excel test, which I bombed - atomically. I remember already being at the verge of tears when the nice HR lady led me to the second room where I was to meet the interview panel, consoling me along the way and giving me well-meaning advice. "&lt;em&gt;Don't worry - you can make up for this! Go meet the panel with your head held high!&lt;/em&gt;" &lt;/p&gt;

&lt;p&gt;Heeding her advice, I held my head high as I promptly proceeded to knock over the glass of water the panel had prepared for me. &lt;em&gt;Excellent start&lt;/em&gt;. The rest of the interview went by in a similar fashion, and by the end of it, it was clear to everyone and their mum that I didn't want the job, they didn't want to hire me, and that it was absurd we were all in the same room. When I got asked what topic's addition to their institution's curriculum graduates might benefit from, I went silent for a couple of seconds, then laughed and said, as a graduate of said institution, "Interview Skills". The joke landed. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;An Exact, Unexaggerated Replica of My Mental State Post-Interview&lt;/em&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/3o6Ztq9bsJps4ljwZ2/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o6Ztq9bsJps4ljwZ2/source.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this tragic event I took the dramatic vow to &lt;strong&gt;never ever ever EVER interview for anything EVER again&lt;/strong&gt;. I would die poor and hungry, but save myself the humiliation of continuously competing for and losing out on something I found deeply uninspiring. &lt;/p&gt;

&lt;h3&gt;
  
  
  🏡 Lockdown 🏡
&lt;/h3&gt;

&lt;p&gt;Fast forward 2 months. It's now April 2020. Lockdown has robbed me of any distractions. I have ample time on my hands and I choose to invest it in learning new things. First, I do a Harvard MOOC on the chemistry of cooking. Many mouldy kombucha attempts and a now 12th-generation sour-dough starter called Bob later, I abandon my culinary aspirations and decide to replace pretending to be a Masterchef with watching Masterchef. &lt;/p&gt;

&lt;h3&gt;
  
  
  🖥️ Enter Coding 🧮
&lt;/h3&gt;

&lt;p&gt;What could I learn next? How about something I've always found fascinating, incredibly cool but equally intimidating? There was no time pressure, for what seemed like the first time in years. I might as well get creative. Having a history of ascribing God-like qualities to and immediately falling in love with anyone capable of using a terminal, I knew just what I wanted to attempt to learn next: &lt;strong&gt;coding&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;me, in love, after seeing virtually anyone use a terminal&lt;/em&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/PFo2HrqCjC0bm/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/PFo2HrqCjC0bm/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  😻 Colt Steele, The Absolute Legend 🐔
&lt;/h3&gt;

&lt;p&gt;I was lucky to stumble upon Colt Steele's &lt;a href="https://www.udemy.com/course/the-modern-python3-bootcamp/" rel="noopener noreferrer"&gt;modern Python bootcamp&lt;/a&gt;. I purchased in on sale, and it remains the best £14 I've ever spent in my entire life. (&lt;em&gt;I pity the fool that purchases a full-price Udemy course - there's a sale almost every month.&lt;/em&gt;) I have come to be a great fan of his teaching style and admire the rigour and depth he applies to explaining concepts. Before I knew it, I was dreaming about writing code. &lt;/p&gt;

&lt;p&gt;I imagine that at this point, my story could have easily branched off in a different direction. I could have abandoned coding the second it got tricky, and thrown my Mac out along with the last remnants of my misguided fermentation attempts. But it felt like something had clicked - turns out, programming perfectly encapsulated everything I had always known I was quite good at and loved doing, namely: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;creative problem-solving&lt;/strong&gt; (&lt;em&gt;nobody ever tells you how inherently creative coding actually it - but it is!&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;logical/analytical thinking&lt;/strong&gt; (&lt;em&gt;a trait that wasn't always beneficial in my previous industry - mental health&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;striving for efficiency&lt;/strong&gt; (&lt;em&gt;I am half-German, after all...&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;learning new things&lt;/strong&gt; (&lt;em&gt;turns out, there's no shortage of things to learn in the realm of code&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  💻 Pursuing Tech Professionally 💻
&lt;/h3&gt;

&lt;p&gt;I got asked what precipitated my decision to pursue coding professionally during one of my interviews. I'm not sure I gave a good answer to this, because in reality, I didn't just wake up one morning and decide "&lt;em&gt;right, tech is where it's at&lt;/em&gt;". &lt;strong&gt;My decision was forming over a number of months, as I explored Python, and later JavaScript and web development via cheap/free online courses.&lt;/strong&gt; I was becoming more and more convinced that I didn't just thoroughly enjoy coding - I was also good at it, and learning at a fast enough pace that I could imagine myself, in the distant future, being quite adept at it. &lt;/p&gt;

&lt;p&gt;This was a surprising finding. I grew up in 90s Slovakia, and encountered no computers in educational settings. Computer science seemed like a field reserved for a select few boys who spent their teenage years hacking away. By the time I was 18, I already considered myself too old to catch up and &lt;strong&gt;a career in tech, consequently, never even seemed to be within my realm of possibility.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm not saying that there are 0 Slovak women my age who were independent and brave enough to become software engineers, but on average, the cultural norm fed girls some limiting beliefs that took me almost a decade to dismantle. &lt;/p&gt;

&lt;h3&gt;
  
  
  🩹 The Ugly Bits 🩹
&lt;/h3&gt;

&lt;p&gt;I prefaced this article with a promise to be fully transparent. These early months of learning to code from scratch were not exactly a walk through a rose garden. There were many days when I doubted my ability to learn. Not every topic immediately clicked with me - I cried over async JavaScript and for some reason, Axios (which I now love). I also cried over CSS, but who hasn't. It took me a while to adopt a beneficial mindset and stop seeing every bug or knowledge gap as a personal failure. I'm a billion times better at it now, but I'm still not perfect. This is a normal part of the learning process, I'm told. &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%2Fgem10cpcr331qmtywqlk.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%2Fgem10cpcr331qmtywqlk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Programming is an amazing way of getting comfortable with failing and accepting failure as a good thing. You &lt;em&gt;will&lt;/em&gt; fail over and over again, and that's okay - it's the only way to learn. &lt;strong&gt;I find it amazing that I found a perfect metaphor for life inside a computer.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🎓 Finding the Right Bootcamp 🎓
&lt;/h3&gt;

&lt;p&gt;Once I realised I wanted to transition to tech professionally, I decided to attend a bootcamp. Learning from a structured curriculum curated by expert teachers appealed to me, and the prospect of receiving a certificate to prove my skill felt like the right way to approach my job hunt. I attended &lt;a href="https://www.springboard.com/" rel="noopener noreferrer"&gt;Springboard's&lt;/a&gt; remote-first software engineering bootcamp, designed by Colt Steele The Absolute Legend and Rithm School, one of the world's top 10 bootcamps according to &lt;a href="https://www.switchup.org/rankings/best-coding-bootcamps" rel="noopener noreferrer"&gt;SwitchUp&lt;/a&gt; (&lt;em&gt;note: Colt Steele doesn't actually refer to himself as an Absolute Legend and would likely sigh disappointedly at my doing so. He does have a chicken called Stevie Chicks, however, which proves my moniker correct.&lt;/em&gt;). &lt;/p&gt;

&lt;p&gt;I was lucky to have half of my tuition waived. Although, I'm not sure "lucky" is an appropriate word choice here - my tuition was waived due to Springboard's scheme to help out 2 students per cohort who have suffered financially in the pandemic. By August 2020, most of my sources of income had dried up, and I was receiving government assistance. &lt;/p&gt;

&lt;p&gt;I did continue working for a couple of mental health organisations as a contractor, which is part of the reason I chose a remote, self-paced bootcamp. It gave me the freedom to keep working to support myself at least somewhat. &lt;/p&gt;

&lt;h3&gt;
  
  
  🏋️‍♀️ Turns Out, Bootcamps Are Intense 🏋️‍♀️
&lt;/h3&gt;

&lt;p&gt;My dedication towards splitting my time between working and studying evenly faded about three months into the bootcamp. &lt;strong&gt;I made the difficult decision to leave one of my contracting gigs behind&lt;/strong&gt;. This felt risky - I already had a tiny income, so reducing it further seemed like a silly idea. But I wanted to put my energy and time where it mattered most - coding, and I didn't like the feeling of falling behind the suggested learning pace because I often had to prioritise work over learning.&lt;/p&gt;

&lt;p&gt;The bootcamp was not easy, especially the first couple of months. It often felt lonely and frustrating. I didn't have a cohort to get to know or grow alongside of - all I had was a Slack channel which barely anyone used, and my best pal Google. Whilst I missed out on the social aspect of bootcamps due to the remote nature of mine, the course more than made up for this with a rigorous and extremely well-designed curriculum that focused on depth rather than breadth. &lt;strong&gt;I'm convinced that I owe my job-search success in large part to Springboard's flawless curriculum&lt;/strong&gt;, and no, I'm not being paid to say this. &lt;/p&gt;

&lt;h3&gt;
  
  
  🔎 Job Search 🔍
&lt;/h3&gt;

&lt;p&gt;At the 90% mark of my bootcamp, I started saying yes to recruiters approaching me on LinkedIn. Initially, I saw this as a good strategy to learn how to interview well, so that by the time I applied for my dream role, I would be ready. But my first ever interview process was with Trustpilot, and it quickly became apparent that I didn't just want to use this opportunity to "practice" - this was THE job, and I wanted it badly. I landed the role, less than a year after I wrote my first line of code. I'm hoping to share useful interview advice in an article that will come later in this series, so if you're keen to hear more, bookmark this. &lt;/p&gt;

&lt;h3&gt;
  
  
  ✨ Luck ✨
&lt;/h3&gt;

&lt;p&gt;As mentioned in the intro, I want to acknowledge the privilege I benefited from. First of all, I spent the year in a supportive and safe environment, and as someone who hasn't always had this, I've come to understand how crucial feeling safe is to personal development. It's nearly impossible to change your life when you have to spend energy on worrying about your own physical or emotional safety. &lt;/p&gt;

&lt;p&gt;The world also kindly decided to go nuts and rob me of any distractions as I spent my days, weeks and months writing code. I am not in any shape or form glad that the pandemic happened, but I do need to acknowledge that one of its repercussions was me suddenly having all the time in the world to examine my life. &lt;/p&gt;

&lt;p&gt;My partner is my number 1 fan and the world's best &lt;a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging" rel="noopener noreferrer"&gt;rubber-ducky&lt;/a&gt;. Whilst he's not in tech, he is fluent in Python, and his knowledge helped me immensely over the first couple of months. It also helped that, once I quit one of my admin jobs, I only had one part-time gig left and was pretty free to code on most day. Many others in my bootcamp were completing it alongside a full-time job or parental duties. My hat goes off to anyone who is a caretaker or juggling a full-time job whilst re-skilling. You're literally the most inspiring people in the Universe.&lt;/p&gt;

&lt;p&gt;I also got lucky that a company with values that 100% overlap mine decided to hire a junior at exactly the time I began feeling ready for a job. What is more - the hiring manager, an inspiring person with a plethora of online public speaking videos, specifically told the recruiters that a computer science degree was not a pre-requisite for the role. Had this not been the case, I might have never heard about the position. &lt;/p&gt;

&lt;p&gt;I will not go into a philosophical debate here, but I will say that I don't believe we have a lot of influence over the luck in our life, and I also don't believe we can "manifest" opportunities by the sheer power of our thoughts, as per The Secret. &lt;strong&gt;The Real Secret is, in my near-scientific and not at all subjective opinion, that hard work prepares us to benefit from those moments in our life when we experience random positive spikes in our fortune.&lt;/strong&gt; So if you make smart choices and spend your energy wisely, you will be more likely to find yourself in a position where you can fully capitalise on random fortuitous opportunities, once they present themselves to you. And in time they likely will, because, well - statistics.&lt;/p&gt;

&lt;p&gt;So, in conclusion... &lt;strong&gt;No, it's not too late to switch careers, and yes, you can do it too. Good &lt;del&gt;luck&lt;/del&gt; hard work!  ✨✨✨✨&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>career</category>
      <category>beginners</category>
      <category>wecoded</category>
    </item>
    <item>
      <title>I Got a Tech Job in Under a Year. Here's How.</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Tue, 13 Apr 2021 19:53:31 +0000</pubDate>
      <link>https://dev.to/sanspanic/i-got-a-tech-job-in-under-a-year-here-s-how-536p</link>
      <guid>https://dev.to/sanspanic/i-got-a-tech-job-in-under-a-year-here-s-how-536p</guid>
      <description>&lt;p&gt;&lt;em&gt;"Is this... an April fool's joke?"&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;...is what I asked the recruiter when he called me on the 1st of April to let me know I had gotten the job. It felt impossible, too good to be true - this was the first tech role I'd ever applied for, after all. Strictly speaking, even saying I applied for it is an exaggeration, because in truth, I was approached by a recruiter on LinkedIn. My portfolio page wasn't up yet (it still isn't), and my bootcamp was only 90% finished. On paper, I was less ready than many others out there. &lt;strong&gt;I couldn't believe my luck - I had actually secured a job offer from one of Europe's fastest growing tech companies.&lt;/strong&gt; For someone with no computer science degree and a background in mental health and administration, this was life-changing stuff.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;actual footage of my impostor syndrome kicking in the second I got the job&lt;/em&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/l3q2WKTvXa4AEC0xO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l3q2WKTvXa4AEC0xO/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Despite what the admittedly clickbait-y title of this article suggests, it will not focus on me blowing my own trumpet and letting everyone know just how smart and uniquely awesome I am (&lt;em&gt;although, of course I am...&lt;/em&gt; 😏). Instead, &lt;strong&gt;I will offer some well-meaning advice and talk openly about my often challenging but ultimately rewarding experience of transitioning careers from mental health to tech in under a year, warts and all.&lt;/strong&gt; I will let you know what I did to get to where I am now, but importantly, I will also acknowledge the large role circumstances outwith my control played over the last year.&lt;/p&gt;

&lt;p&gt;Don't get me wrong - &lt;strong&gt;I've worked incredibly hard for this&lt;/strong&gt; - sweat, blood and literal tears went into the process. Of course I think I deserve the company's faith and I'm determined to continue growing and proving myself worth their trust. But I want to qualify my success with external factors that helped me get here. &lt;/p&gt;

&lt;p&gt;I've previously caught myself feeling jealous of people who wrote similar articles without acknowledging how much luck or support they had along the way. Social media is by design a place where we share our highlight reels, and more often than not, we remain silent about the uglier parts of our lives, or the privilege we get to benefit from. &lt;strong&gt;My aim is to be fully transparent,&lt;/strong&gt; and in doing so, prevent anyone reading this from feeling bad about themselves just because their job search or learning process might be taking longer than mine did.&lt;/p&gt;

&lt;p&gt;So whether you are a newbie starting to learn how to code or a bootcamp-graduate already in the market for your first tech job, keep reading, this series of articles is for you. &lt;strong&gt;You've got this. I promise.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The focus of this series will be split across 3 topics, which I'll release over the coming days. If you're more interested in practical advice than my journey, fair enough, feel free to skip ahead to Part 2. &lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;a href="https://dev.to/sanspanic/my-coding-journey-becoming-a-software-engineer-in-under-1-year-12de"&gt;My Coding Journey - the Good, the Bad, the Ugly&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  2. &lt;a href="https://dev.to/sanspanic/coding-advice-i-wish-i-d-trusted-earlier-f1f"&gt;What I Wish I Knew When I Started Coding&lt;/a&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  3. Interview Advice
&lt;/h3&gt;

</description>
      <category>motivation</category>
      <category>career</category>
      <category>beginners</category>
      <category>wecoded</category>
    </item>
    <item>
      <title>Pure vs Impure Functions</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Thu, 18 Mar 2021 15:05:33 +0000</pubDate>
      <link>https://dev.to/sanspanic/pure-vs-impure-functions-50aj</link>
      <guid>https://dev.to/sanspanic/pure-vs-impure-functions-50aj</guid>
      <description>&lt;p&gt;Software engineering is full of jargon. Occasionally, to grasp the true meaning of the seemingly simplest of words, one must waddle through many murky layers of complexity (fancy defining &lt;code&gt;this&lt;/code&gt;, anyone?). Thankfully, other times, outwardly inaccessible words can be demystified pretty easily. In this article, we'll deal with the latter case, breaking down &lt;strong&gt;pure&lt;/strong&gt; vs &lt;strong&gt;impure&lt;/strong&gt; functions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;person thinking about the definition of &lt;code&gt;this&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;a href="https://i.giphy.com/media/lnPELPXua4cGq4QlQZ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/lnPELPXua4cGq4QlQZ/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Pure Functions 👼
&lt;/h2&gt;

&lt;p&gt;To be considered pure, functions must fulfil the following criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;they must be predictable&lt;/li&gt;
&lt;li&gt;they must have no side effects&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  ➡️ Pure functions must be predictable.
&lt;/h5&gt;

&lt;p&gt;Identical inputs will always return identical outputs, no matter how many times a pure function is called. In other words: we can run a pure function as many times as we like, and given the inputs remain constant, the function will always predictably produce the same output. Kind of like when you're a pizza-loving person with lactose intolerance. &lt;em&gt;No, this time won't be different, so stop ogling that 16-incher your flatmate ordered.&lt;/em&gt;&lt;/p&gt;
&lt;h5&gt;
  
  
  ➡️ Pure functions must have no side-effects.
&lt;/h5&gt;

&lt;p&gt;A side-effect is any operation your function performs that is not related to computing the final output, including but not limited to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modifying a global variable&lt;/li&gt;
&lt;li&gt;Modifying an argument&lt;/li&gt;
&lt;li&gt;Making HTTP requests&lt;/li&gt;
&lt;li&gt;DOM manipulation&lt;/li&gt;
&lt;li&gt;Reading/writing files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A pure function must both be predictable and without side-effects. If either of these criteria is not met, we're dealing with an impure function.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;impure&lt;/strong&gt; function is kind of the opposite of a pure one - it doesn't predictably produce the same result given the same inputs when called multiple times, and may cause side-effects. Let's have a look at some examples.&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;// PURE FUNCTION 👼&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pureAdd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&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="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//always returns same result given same inputs&lt;/span&gt;
&lt;span class="nx"&gt;pureAdd&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;5&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;pureAdd&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;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//10&lt;/span&gt;

&lt;span class="c1"&gt;//IMPURE FUNCTION 😈&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;plsMutateMe&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;impureAdd&lt;/span&gt; &lt;span class="o"&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="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;plsMutateMe&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="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//returns different result given same inputs&lt;/span&gt;
&lt;span class="nx"&gt;impureAdd&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;//5&lt;/span&gt;
&lt;span class="nx"&gt;impureAdd&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;//10&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;plsMutateMe&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//10 🥳 I'm now double digit, yay!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, the impure version of the function both changes a variable outside its scope, and results in different output, despite being called with identical input. This breaks both rules of pure functions and as such, it's pretty clear we're dealing with an impure function here. &lt;/p&gt;

&lt;p&gt;But let's have a look at an example of an impure function that is not so easy to tell apart from its pure counterpart.&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;//IMPURE FUNCTION 😈&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;impureAddToArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;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="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;impureAddToArray&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="c1"&gt;//[1,2,3,4]&lt;/span&gt;
&lt;span class="nx"&gt;impureAddToArray&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="c1"&gt;//[1,2,3,4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given the same inputs, the function above will always return the same output. But it also has the side effect of modifying memory in-place by pushing a value into the original input array and is therefore still considered impure. Adding a value to an array via a pure function instead can be achieved using the spread operator, which makes a copy of the original array without mutating it.&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;//IMPURE FUNCTION 😈&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;impureAddToArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;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="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//altering arr1 in-place by pushing 🏋️&lt;/span&gt;
  &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// PURE FUNCTION 👼&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pureAddToArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;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="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;arr1&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at how we'd add to an object instead.&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;// IMPURE FUNCTION 😈&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;impureAddToObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;val&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="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;val&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;obj&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;Because we're modifying the object in-place, the above approach is considered impure. Below is its pure counterpart, utilising the spread operator again.&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;// PURE FUNCTION 👼&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt;  &lt;span class="nx"&gt;pureAddToObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;val&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="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;val&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;h2&gt;
  
  
  Why should I care?
&lt;/h2&gt;

&lt;p&gt;If the differences in the above examples seem negligible, it's because in many contexts, they are. But in a large-scale application, teams might choose pure over impure functions for the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pure functions are easy to test, given how predictable they are&lt;/li&gt;
&lt;li&gt;Pure functions and their consequences are easier to &lt;em&gt;think&lt;/em&gt; about in the context of a large app, because they don't alter any state elsewhere in the program. Reasoning about impure functions and potential side-effects is a greater cognitive load. &lt;/li&gt;
&lt;li&gt;Pure functions can be memoized. This means that their output, given certain inputs, can be cached when the function first runs so that it doesn't have to run again - this can optimise performance.&lt;/li&gt;
&lt;li&gt;The team lead is a Slytherin obsessed with the purity status of both blood and functions (&lt;em&gt;are we too old for HP references? I think not&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pure functions are also the foundation of functional programming, which is a code-writing paradigm entire books have been written about. Moreover, some popular libraries require you to use pure functions by default, for example React and Redux. &lt;/p&gt;

&lt;h2&gt;
  
  
  Pure vs Impure JavaScript Methods
&lt;/h2&gt;

&lt;p&gt;Certain JS functions from the standard library are inherently impure. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Math.random()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Date.now()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.splice()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.push()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.sort()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Conversely, the below JS methods are typically associated with pure functions.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;arr.map()&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.filter()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr.reduce()&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr.each()&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arr.every()&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.concat()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;arr.slice()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Math.floor()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;str.toLowerCase()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;the spread syntax &lt;code&gt;...&lt;/code&gt; is also commonly used to create copies&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Comparison
&lt;/h2&gt;

&lt;p&gt;So who comes out as a winner in this battle between good and evil? Actually, &lt;em&gt;nobody&lt;/em&gt;. They simply have different use cases, for example, neither AJAX calls, nor standard DOM manipulation can be performed via pure functions. And impure functions aren't intrinsically bad, they just might potentially lead to some confusion in the form of spaghetti code in larger applications.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sidenote: I resent the widely held sentiment that the word spaghetti should ever be associated with anything negative. Get in my tummy and out of coding lingo, beloved pasta. 🍝&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I'll leave you with a quick &lt;strong&gt;tl;dr&lt;/strong&gt; comparison table. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;👼 Pure Functions 👼&lt;/th&gt;
&lt;th&gt;😈 Impure Functions 😈&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no side-effects&lt;/td&gt;
&lt;td&gt;may have side-effects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;returns same result if same args passed in no matter how many times it runs&lt;/td&gt;
&lt;td&gt;may return different result if same args passed in on multiple runs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;always returns something&lt;/td&gt;
&lt;td&gt;may take effect without returning anything&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;is easily testable&lt;/td&gt;
&lt;td&gt;might be harder to test due to side-effects&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;is super useful in certain contexts&lt;/td&gt;
&lt;td&gt;is also super useful in certain contexts&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>redux</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Implementing Dark Mode in React via Context</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Wed, 03 Mar 2021 13:48:18 +0000</pubDate>
      <link>https://dev.to/sanspanic/implementing-dark-mode-in-react-via-context-4f1p</link>
      <guid>https://dev.to/sanspanic/implementing-dark-mode-in-react-via-context-4f1p</guid>
      <description>&lt;p&gt;One would think the timeline we live in is dark enough, but for some reason, developers are obsessed with giving users the option to make their lives even darker. In this article, we will go over how to implement toggling between dark and light mode in React. We'll also have a closer look at React Context, the tool we'll be using to achieve this. &lt;/p&gt;

&lt;p&gt;Let's start with a simple React app with 6 components: a Button, a Navbar, as well as a nested "family" consisting of Grandparent, Parent, Child and Baby. Our top-most App component includes Navbar and GrandParent, and GrandParent in turn contains Parent, which contains Child, which contains Baby. &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;App&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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GrandParent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;Let's assume, for ease of variable naming, that it's perfectly logical for a child to have a baby, and for this baby to have a grandparent instead of a great-grandparent. Now that our disbelief is suspended, let's look at what this might look like in light mode below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9j81et49o56j89i379eo.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%2F9j81et49o56j89i379eo.png" alt="Screenshot showing nested components in light mode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sidenote: the monstrosity above acts as a nice segue into letting you know that clearly, the focus of this article will not be CSS, but the implementation of the React logic which enables us to easily switch between CSS classes across all components. If you're looking for aesthetically pleasing dark mode CSS, keep looking, and best of luck to you.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The aim is to eventually end up in a place where the user can toggle between the current light mode and dark mode by simply clicking on a toggle switch or icon in the Navbar. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Add Toggle Switch / Icon
&lt;/h3&gt;

&lt;p&gt;Toggle switches are actually heavily styled inputs of the type checkbox. Nobody implements toggle switches from scratch. Nobody. Not a single person. &lt;em&gt;Unless they like CSS, which I hear can be the case for a select few&lt;/em&gt; 😯 So let's grab some code, for example from &lt;a href="https://www.w3schools.com/howto/howto_css_switch.asp" rel="noopener noreferrer"&gt;here&lt;/a&gt;, and add our switch to the navbar. You could also instead add buttons wrapped around sun/moon icons, for example from &lt;a href="https://fontawesome.com/how-to-use/on-the-web/using-with/react" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Our page now looks like this: &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%2Fo0j43e7rzui63bx8mxrh.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%2Fo0j43e7rzui63bx8mxrh.png" alt="Light theme with added toggler switch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Beautiful!&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Share Data Between Components
&lt;/h3&gt;

&lt;p&gt;To implement dark mode, we'll need to find a way to share data between components efficiently. Let's say that in our example, the GrandParent component wanted to share something with the Baby component. One way to do this would be to define a variable or piece of state at the GrandParent level and pass it down via the Parent and Child components all the way to the Baby component, like so: &lt;/p&gt;

&lt;p&gt;The GrandParent defines the variable and passes it down to the Parent. &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;GrandParent&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Toxic by B. Spears&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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GrandParent-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Parent&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;AM&lt;/span&gt; &lt;span class="nx"&gt;THE&lt;/span&gt; &lt;span class="nx"&gt;GRANDPARENT&lt;/span&gt; &lt;span class="err"&gt;👵&lt;/span&gt;  &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt; &lt;span class="nx"&gt;fav&lt;/span&gt; &lt;span class="nx"&gt;song&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;The Parent destructures the grandmasFavSong prop and passes it down to Child. Arduous...&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;Parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Parent-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Child&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;AM&lt;/span&gt; &lt;span class="nx"&gt;THE&lt;/span&gt; &lt;span class="nx"&gt;PARENT&lt;/span&gt; &lt;span class="err"&gt;👩&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;The Child now also has to destructure the prop and pass it down to the Baby component. 🥱🥱🥱&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;Child&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Child-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Baby&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;AM&lt;/span&gt; &lt;span class="nx"&gt;THE&lt;/span&gt; &lt;span class="nx"&gt;CHILD&lt;/span&gt; &lt;span class="err"&gt;🧒&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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, the Baby component knows of Grandma's secret obsession.&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;Baby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Baby-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;AM&lt;/span&gt; &lt;span class="nx"&gt;THE&lt;/span&gt; &lt;span class="nx"&gt;BABY&lt;/span&gt; &lt;span class="err"&gt;🍼&lt;/span&gt;  &lt;span class="nx"&gt;why&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;grandma&lt;/span&gt; &lt;span class="nx"&gt;making&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt; &lt;span class="nx"&gt;listen&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;??&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;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%2F7qjx1mrco6jvnq9lv84a.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%2F7qjx1mrco6jvnq9lv84a.png" alt="Prop Drilling demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might have noticed that this is not a very elegant way of achieving data sharing between components. Doing this is known as &lt;strong&gt;prop drilling&lt;/strong&gt;. It's considered bad practice and should be avoided, much like its cousins oil drilling &amp;amp; tooth drilling. Best to just avoid drilling of any kind. Thankfully, React provides a neat alternative. &lt;/p&gt;

&lt;h3&gt;
  
  
  Enter React Context.
&lt;/h3&gt;

&lt;p&gt;In life as well as in React, &lt;strong&gt;context is key&lt;/strong&gt;. React Context provides a way to share data between components without having to pass it down as a prop through each level of the component hierarchy. Using said React Context is a better way to share grandma's unhealthy obsession with 2000s pop than what we've seen above. The workflow is as follows: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Context &lt;/li&gt;
&lt;li&gt;Add the data intended to be shared to Context&lt;/li&gt;
&lt;li&gt;Wrap a Context provider around the components that need access to it&lt;/li&gt;
&lt;li&gt;Consume the Context provider wherever needed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's go through this step by step. &lt;/p&gt;

&lt;h5&gt;
  
  
  1. Create Context
&lt;/h5&gt;

&lt;p&gt;We'll do this in a new file called MusicContext.js: &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;That's all? Yep, that's all. &lt;/p&gt;

&lt;h5&gt;
  
  
  2. Add the data intended to be shared to Context
&lt;/h5&gt;

&lt;p&gt;Let's create a new file called MusicProvider.js. We'll define our data here, and use the &lt;code&gt;children&lt;/code&gt; prop to make sure every component the MusicProvider is wrapped around has access to our values. &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MusicContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./MusicContext&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;MusicProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Toxic by B. Spears&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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MusicContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&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="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/MusicContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MusicProvider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;
&lt;h5&gt;
  
  
  3. Wrap the Context provider around relevant components
&lt;/h5&gt;

&lt;p&gt;In this case, we don't need our Navbar to have access to the data, but we do want GrandParent and Baby to have access. And so, we'll wrap the provider around GrandParent, within which all the other Family components are nested. &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;import&lt;/span&gt; &lt;span class="nx"&gt;MusicProvider&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Context/MusicProvider&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MusicProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GrandParent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/MusicProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;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;h5&gt;
  
  
  4. Consuming Context wherever needed
&lt;/h5&gt;

&lt;p&gt;We want to display the data in the GrandParent and Baby components. We'll need to take the following steps in each of the files: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Import the useContext hook from React&lt;/li&gt;
&lt;li&gt;Import MusicContext (&lt;strong&gt;not&lt;/strong&gt; MusicProvider)&lt;/li&gt;
&lt;li&gt;Extract the variable out of Context &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's look at how to do this is the Baby component: &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Family.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MusicContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../Context/MusicContext&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;Baby&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="c1"&gt;// extracting variable from context ⬇️⬇️&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MusicContext&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Baby-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;AM&lt;/span&gt; &lt;span class="nx"&gt;THE&lt;/span&gt; &lt;span class="nx"&gt;BABY&lt;/span&gt; &lt;span class="err"&gt;🍼  &lt;/span&gt;&lt;span class="nx"&gt;why&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;grandma&lt;/span&gt; &lt;span class="nx"&gt;making&lt;/span&gt; &lt;span class="nx"&gt;me&lt;/span&gt; &lt;span class="nx"&gt;listen&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;grandmasFavSong&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;??&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Baby&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;After doing the same for GrandParent, our app should look as it did before. Whilst it's not immediately obvious that this is a more efficient way of sharing data between components than prop drilling in our tiny app, trust me when I tell you that the utility of using Context scales with application size and number of components. &lt;/p&gt;

&lt;h3&gt;
  
  
  What about dark mode?
&lt;/h3&gt;

&lt;p&gt;Now that we understand React Context, let's use it to implement dark mode. There's many ways to achieve this, but here we'll use the class &lt;code&gt;dark&lt;/code&gt; and associate it with dark-mode styling in our CSS. The class &lt;code&gt;dark&lt;/code&gt; will be rendered in relevant components conditionally using the ternary operator. Let's use our Button component as an example: &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Button.css&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;Button&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;darkMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dark&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`Button-btn &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;darkMode&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="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dark&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;Light &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Now, let's follow through the same steps as when we were handling music Context. &lt;/p&gt;

&lt;h5&gt;
  
  
  1. Create The Context in ThemeContext.js:
&lt;/h5&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;


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

&lt;/div&gt;
&lt;h5&gt;
  
  
  2. Add values to the Context provider
&lt;/h5&gt;

&lt;p&gt;We'll define our state, isDark, in a file called ThemeProvider.js. We will also define a function that toggles isDark. Both will be passed to the provider's children as Context values. This time, since we have more than one value, we'll wrap them in an object. &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./ThemeContext&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;ThemeProvider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsDark&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&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;toggleMode&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="nf"&gt;setIsDark&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;mode&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ThemeContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Provider&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleMode&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="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ThemeContext.Provider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ThemeProvider&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;
&lt;h5&gt;
  
  
  3. Wrap the Context provider around relevant components
&lt;/h5&gt;

&lt;p&gt;This time, we'll want to wrap it around all components, including our Navbar.&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;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;GrandParent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Family/GrandParent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Family/Family.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Navbar/Navbar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MusicProvider&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Context/MusicProvider&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ThemeProvider&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Context/ThemeProvider&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ThemeProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Navbar&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MusicProvider&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;GrandParent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/MusicProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ThemeProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;
&lt;h5&gt;
  
  
  4. Consuming Context wherever needed
&lt;/h5&gt;

&lt;p&gt;Let's again use our Button component as an illustration: &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Button.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../Context/ThemeContext&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;Button&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ThemeContext&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;darkMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dark&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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`Button-btn &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;darkMode&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="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dark&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;Light &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;After following a similar approach in each component that we want to be affected by the mode changing, the only thing left to do is to implement its toggling. We're already sharing the toggle function via Context, so let's grab it where we need it: in the ToggleSwitch component. We'll create an event that fires on click and triggers the mode toggling. &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;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./ToggleSwitch.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../Context/ThemeContext&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;ToggleSwitch&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;toggleMode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isDark&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ThemeContext&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ToggleSwitch-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;switch&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggleMode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;checkbox&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;slider round&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/label&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ToggleSwitch&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Rejoice! 👏👏👏 We're done. Now our app looks like this, or indeed much much better, depending on how much effort we put in our CSS. &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%2Fafx2dgbriqxeye3s027d.gif" 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%2Fafx2dgbriqxeye3s027d.gif" alt="GIF of toggling between light and dark modes"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Effect Hook Explained</title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Mon, 15 Feb 2021 20:35:34 +0000</pubDate>
      <link>https://dev.to/sanspanic/react-effect-hook-explained-4npg</link>
      <guid>https://dev.to/sanspanic/react-effect-hook-explained-4npg</guid>
      <description>&lt;p&gt;I've recently learned about React's inbuilt &lt;code&gt;useEffect&lt;/code&gt; hook and let me tell you - it's neat! 💙 It's commonly used to retrieve data from external APIs and handle timers. This article will walk you through a step-by-step implementation of a timer component via the &lt;code&gt;useEffect&lt;/code&gt; hook. &lt;/p&gt;

&lt;p&gt;Let's say our timer component should update each second, like so: &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%2Fi%2Fsujc2do0pjeef432bk2w.gif" 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%2Fi%2Fsujc2do0pjeef432bk2w.gif" alt="Timer working"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're new to React, you might be tempted to define an interval at the top level of your component, as 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./TimerDemo.css&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;TimerDemo&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="nf"&gt;setInterval&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="nf"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&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;s&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="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TimerDemo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Timer&lt;/span&gt; &lt;span class="nx"&gt;Demo&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;⌛&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="err"&gt;⌛&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;TimerDemo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, the above code will result in the following output. &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%2Fi%2Fnwslr03dhxkawm9qaar3.gif" 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%2Fi%2Fnwslr03dhxkawm9qaar3.gif" alt="Timer going mad"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What's going on here? Has React broken the Universe and altered the rules of spacetime? 👽 Not quite. What's happening here is that multiple intervals are being set over and over in quick succession. &lt;/p&gt;

&lt;p&gt;When the component renders for the first time, the interval is set, which changes the state of &lt;code&gt;seconds&lt;/code&gt; each second. Once the state changes, a re-render of the entire component is immediately triggered, and the code inside the component runs once more. Upon running, the code will result in another, identical, interval being set. But the old interval will also continue doing its thing and manipulating the state of &lt;code&gt;seconds&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;So now we have two intervals that are both behaving the same way: updating state each second and triggering the component to re-render. Each re-render will lead to more fresh intervals being set, which in turn will trigger state change. This cycle - a positive feedback loop - will repeat ad infinitum (or more likely ad browser-crashium). 🔁&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The correct way to handle timers in React is by using the splendiferous &lt;code&gt;useEffect&lt;/code&gt; hook.&lt;/strong&gt; The top 3 things to know about this hook are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it accepts a &lt;em&gt;callback function&lt;/em&gt; as the 1st argument&lt;/li&gt;
&lt;li&gt;it accepts an &lt;em&gt;array&lt;/em&gt; as its optional 2nd argument&lt;/li&gt;
&lt;li&gt;it returns null, but can optionally be customised to return a &lt;em&gt;function&lt;/em&gt;, which is useful for "cleanup" purposes&lt;/li&gt;
&lt;li&gt;it's hard to represent emojitively, because there isn't yet cross-browser support for the hook emoji, so here's an anchor instead ⚓ (okay, this one was a bonus)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll examine how each of these points relates to handling timers in React. (Except the emoji one. Which doesn't.) &lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;useEffect&lt;/code&gt; Callback Function
&lt;/h3&gt;

&lt;p&gt;The first argument the hook accepts is a callback function. This function is what React understands to be the "effect". In this case, the effect is our interval. Let's define it inside a &lt;code&gt;useEffect&lt;/code&gt; hook.&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;TimerDemo&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="nf"&gt;useEffect&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="nf"&gt;setInterval&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="nf"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&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;s&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="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TimerDemo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Timer&lt;/span&gt; &lt;span class="nx"&gt;Demo&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;⌛&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="err"&gt;⌛&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;This will display as the following: &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%2Fi%2Fnft8yusmarh7k1ftuaf4.gif" 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%2Fi%2Fnft8yusmarh7k1ftuaf4.gif" alt="Timer still going mad"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not at all what we want, our issue remains. This is where the second argument of the &lt;code&gt;useEffect&lt;/code&gt; hook comes into play. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;useEffect&lt;/code&gt; Dependency Array
&lt;/h3&gt;

&lt;p&gt;The second argument is an optional array of state or prop values, which specify when the effect should run. We have 3 options here: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No array: if the array is left out, as in the previous code snippet, the effect will run after &lt;em&gt;every&lt;/em&gt; render.&lt;/li&gt;
&lt;li&gt;Empty array: the effect runs &lt;em&gt;once&lt;/em&gt; after the initial render. &lt;/li&gt;
&lt;li&gt;Array with state or prop values: the effect runs &lt;em&gt;only&lt;/em&gt; when any of these values change. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In our case, if we passed in &lt;code&gt;[seconds]&lt;/code&gt;, we would tell React to re-run the effect each time the state of &lt;code&gt;seconds&lt;/code&gt; changes. Which would, of course, be completely pointless - in fact, this is exactly what we're trying to avoid. &lt;/p&gt;

&lt;p&gt;And avoid it we can; specifically, by passing in an empty dependency array, &lt;code&gt;[]&lt;/code&gt;. An empty array tells React to only run the effect once, after the component renders for the first time. Let's examine the code 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;TimerDemo&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&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="nf"&gt;useEffect&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="nf"&gt;setInterval&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="nf"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&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;s&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="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&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;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TimerDemo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Timer&lt;/span&gt; &lt;span class="nx"&gt;Demo&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;⌛&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;seconds&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="err"&gt;⌛&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;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%2Fi%2Fsujc2do0pjeef432bk2w.gif" 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%2Fi%2Fsujc2do0pjeef432bk2w.gif" alt="Timer working"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! The timer works now. &lt;/p&gt;

&lt;h3&gt;
  
  
  useEffect Return Function
&lt;/h3&gt;

&lt;p&gt;But what would happen to the interval if we removed the timer component from the DOM? Let's create a scenario where it is removed by wrapping it in another component, Clock, which toggles the timer component. Let's also include a toggle button that removes or adds the timer component to the DOM.&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;Clock&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isHidden&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsHidden&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&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;toggle&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="nf"&gt;setIsHidden&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;hidden&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Clock&lt;/span&gt;&lt;span class="dl"&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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isHidden&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TimerDemo&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Clock-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;toggle&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;Toggle&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;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%2Fi%2F72gr7cv0vo6127twhziz.gif" 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%2Fi%2F72gr7cv0vo6127twhziz.gif" alt="Timer seemingly working as intended"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first glance, removing the TimerDemo component from the DOM appears to work as intended. But upon opening the console, an angry sea of red appears. React is not happy. 😡&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%2Fi%2Fdsv3pvy5rknl2j34uxaj.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%2Fi%2Fdsv3pvy5rknl2j34uxaj.png" alt="Error message"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why is this? Well, when the component is removed, despite disappearing visually, the interval associated with it simply keeps going. There's nothing telling it to stop executing. The interval will proceed to try and update the state of a currently unmounted component, greatly upsetting React in the process. Poor React! 🥺&lt;/p&gt;

&lt;p&gt;So, how do we tell the interval to stop when the component is removed from the DOM? By specifying &lt;code&gt;useEffect&lt;/code&gt;'s return value. By default, it returns null, but we can modify this to return a callback function, which will act as "cleanup". Warning: the cleanup function can feel a bit abstract to read about, and the best way to befriend it is to use it and explore its functionality first-hand. &lt;/p&gt;

&lt;p&gt;The cleanup is executed at the following times: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After the initial rendering, the hook &lt;em&gt;only&lt;/em&gt; invokes the effect. The cleanup function &lt;em&gt;doesn't&lt;/em&gt; run&lt;/li&gt;
&lt;li&gt;On all following re-renderings, the cleanup from the previous effect execution is invoked &lt;em&gt;first&lt;/em&gt;, after which the current effect runs&lt;/li&gt;
&lt;li&gt;The cleanup also runs &lt;em&gt;after&lt;/em&gt; the component is unmounted, i.e. removed from the DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's define our cleanup function. In order to stop an interval, we need to capture the interval ID and pass it into a &lt;code&gt;clearInterval&lt;/code&gt; function (a vanilla JS concept). We'll return this function inside our &lt;code&gt;useEffect&lt;/code&gt; and add some print statements to monitor the sequence of execution.&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;useEffect&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am the effect. PARTY! 🎺 👐 🎉&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;timerId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&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="nf"&gt;setSeconds&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;s&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;s&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="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&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="o"&gt;=&amp;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cleaning up... 🙄 🧹🧼&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timerId&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;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fi%2Frxoarrw7bkrw3blcbvov.gif" 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%2Fi%2Frxoarrw7bkrw3blcbvov.gif" alt="cleanup function demonstration"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, the effect runs when the component is mounted, but never again, due to our 2nd argument, the dependency array, being empty. Therefore, the cleanup function will only run when the component is unmounted, thereby clearing the interval and preventing the error message. The toggle button now works as intended, and React is so happy it can barely contain its excitement. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I hope you are too, after making it through this tutorial! 👏&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>So You Want to Learn React? </title>
      <dc:creator>Sandra Spanik</dc:creator>
      <pubDate>Thu, 04 Feb 2021 18:25:53 +0000</pubDate>
      <link>https://dev.to/sanspanic/so-you-want-to-learn-react-1a60</link>
      <guid>https://dev.to/sanspanic/so-you-want-to-learn-react-1a60</guid>
      <description>&lt;p&gt;I'm pretty sure that Facebook is right up there in the category of Top 5 Innovations with The Most Awful Unintended Consequences Ever. A rising threat to our democracies, it has caused the fragmentation of our collective reality and sent our mental health plummeting. HOWEVER, did you know that Facebook also developed React? 😍  &lt;strong&gt;All is forgiven!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So you want to learn React? Excellent choice, it's great fun! It does require some pre-existing knowledge though. Here's the bare minimum of JavaScript skills to brush up on before attempting to learn React. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Package managers&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. Ternary operator&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. Destructuring&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;4. Array methods - especially map &amp;amp; filter&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;5. Arrow functions&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;6. ES6 modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'll provide a brief example of each of above in this article, but please be aware that there's a lot more to explore about each of the topics listed than I will go into here. &lt;/p&gt;
&lt;h3&gt;
  
  
  1. Package managers
&lt;/h3&gt;

&lt;p&gt;React requires some dependencies to run. For instance, you will be writing JSX, a mixture of HTML and JavaScript, which has to be transpiled into regular JavaScript. React uses &lt;code&gt;Babel&lt;/code&gt; for this. You will also need to install &lt;code&gt;react-dom&lt;/code&gt; to render top-level components. Presumably, you will also want to test your React application and install a testing library. For learning purposes or single-page applications, you might want to install &lt;code&gt;Create React App&lt;/code&gt;, which loads up a fully pre-configured application. &lt;/p&gt;

&lt;p&gt;The easiest way to manage your package ecosystem is by using a package manager such as &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;Yarn&lt;/code&gt;.  &lt;em&gt;Overall, you should really be comfortable with installing dependencies and running scripts with your package manager of choice.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2. The Ternary Operator
&lt;/h3&gt;

&lt;p&gt;If you say 'ternary operator' 3x in a row quickly, you're basically saying "The Terminator". And much like The Terminator, the ternary operator is efficient, nice to look at and designed to save the world from impeding doom (in this case the doom of disorganised code). &lt;/p&gt;

&lt;p&gt;Let's say that in order to be The Terminator, a person only needs to fulfil 2 conditions, namely having a German accent, and an abnormally high muscle mass. In ternary operator form, this could be expressed as:&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="p"&gt;;&lt;/span&gt; 
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fulfilsConditions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;muscleMass&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;abnormally large&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;accent&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;German&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;fulfilsConditions&lt;/span&gt;
  &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The Terminator 💪&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;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Not The Terminator 😥&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;&lt;em&gt;You will see this pattern frequently used in React, where whether or not certain elements are rendered depends on conditions being met.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Destructuring
&lt;/h3&gt;

&lt;p&gt;Destructuring assignment might be confusing when first encountered, but is immensely helpful and a concise way to write code. Alongside other cool superpowers, it is capable of 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;const&lt;/span&gt; &lt;span class="nx"&gt;fruits&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;🍓&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;🍍&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;strawberry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pineapple&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pineapple&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;You can do the same with objects.&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;moreFruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;coconut&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;🥥&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;banana&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;coconut&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;banana&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;moreFruits&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coconut&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// 🥥&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In React, destructuring assignment is used all the time to access props or use state.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Array methods - especially &lt;code&gt;map&lt;/code&gt; &amp;amp; &lt;code&gt;filter&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Everybody loves a bit of &lt;code&gt;Array.map&lt;/code&gt; in their lives. Map takes an array, transforms its elements and returns these in a new array, all without mutating the original array. It transforms the elements by calling a provided function on each of them, as 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;numsArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubleNumsArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;numsArr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;doubleNumsArr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// [4, 8, 50]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're a visual learner, you might find it helpful to consider the following non-code code, where we're transforming each egg in the array into a fried egg by applying fire to it:&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;eggs&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;🥚&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;🥚&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;🥚&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;friedEggs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;eggs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;egg&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;egg&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;friedEggs&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ["🍳", "🍳", "🍳"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Array.filter&lt;/code&gt; is similar, in that it does not mutate the original array and creates a new one. But in this case, each element is tested against a provided function, and only those elements that fulfil the condition the function specifies are added to the returned array. 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;animals&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;🐈 &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;🐖&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;🐖&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;🐶&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;onlyPigs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;animals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;animal&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;animal&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;onlyPigs&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;Both &lt;code&gt;Array.filter&lt;/code&gt; and &lt;code&gt;Array.map&lt;/code&gt; are used extensively in React, especially when manipulating data from external APIs and rendering it as components. They're sometimes even chained together, i.e., filtering the data before transforming it into a renderable format. &lt;em&gt;You'll definitely need to be comfortable with using these methods.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Arrow functions
&lt;/h3&gt;

&lt;p&gt;On a similar note, you should also be comfortable with using ES6 arrow function syntax in general. Specifically, you should understand the difference between an implicit and explicit return, otherwise your bracket game will be off. The following should make sense to you:&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="nx"&gt;addSparkles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boringString&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;boringString&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;//above will evaluate to the same as ⬇️&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addSparkles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boringString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;boringString&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="c1"&gt;//which will evaluate to the same as ⬇️ &lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addSparkles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boringString&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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;boringString&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;/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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addSparkles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please make me more visually appealing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Please make me more visually appealing ✨&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a React context, arrow functions can prevent bugs relating to the use of "this" because they inherit "this" from their enclosing scope. And let's be honest, they look much nicer and save ample space. &lt;em&gt;So, although you can achieve anything that an arrow function does by using older syntax, it is extremely beneficial to learn the ES6 way before delving into React.&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  6. ES6 Modules
&lt;/h3&gt;

&lt;p&gt;Files that use React will typically contain at least &lt;code&gt;import React, { useState } from "react";&lt;/code&gt; at the top of the file and &lt;code&gt;export default MyComponent;&lt;/code&gt; at the bottom. If you are like me and prefer the Python way of handling imports/exports, &lt;em&gt;it will be useful to brush up on how this syntax works.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Is that it? 🧐
&lt;/h1&gt;

&lt;p&gt;While this list is not exhaustive, it is a good benchmark for the skill-level required to fall in love with React. If you are familiar with all of above, congratulations, you are ready for React! But even if you are still shaky on some of these concepts, you might want to delve right in. After all, there's no better way to learn coding than by... well, coding. &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
