<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jonathan Speek</title>
    <description>The latest articles on Forem by Jonathan Speek (@jonathanspeek).</description>
    <link>https://forem.com/jonathanspeek</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%2F91186%2F12436026-519e-4fc6-af39-af57daa4bdc2.png</url>
      <title>Forem: Jonathan Speek</title>
      <link>https://forem.com/jonathanspeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jonathanspeek"/>
    <language>en</language>
    <item>
      <title>Destructuring Arrays in JS</title>
      <dc:creator>Jonathan Speek</dc:creator>
      <pubDate>Thu, 25 Mar 2021 08:11:21 +0000</pubDate>
      <link>https://forem.com/jonathanspeek/destructuring-arrays-in-js-131k</link>
      <guid>https://forem.com/jonathanspeek/destructuring-arrays-in-js-131k</guid>
      <description>&lt;p&gt;A somewhat new tool in JavaScript is &lt;code&gt;destructuring&lt;/code&gt;. Sounds scary, but after working with it a little it becomes less intimidating, I swear. Destructuring allows us to just take a few elements (also works with objects and you'll see it plenty in &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_multiple_exports_from_module"&gt;import statements&lt;/a&gt;) from our array and we can even rename them. Let's have a gander.&lt;/p&gt;

&lt;p&gt;Let's make an array of trees and destructure to grab the first and second trees, separating them from the rest of the trees:&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;trees&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;spruce&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;elm&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;maple&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;aspen&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;walnut&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;tree1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tree2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;otherTrees&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trees&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;tree2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;elm&lt;/span&gt;&lt;span class="dl"&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;otherTrees&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;maple&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;aspen&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;walnut&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;What we're doing here is creating a new variable that holds the element at index 0, setting it equal to &lt;code&gt;tree1&lt;/code&gt;, doing the same with index 1 of our trees array, then spreading the rest of the trees into a new variable called &lt;code&gt;otherTrees&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This also works for any number of elements you want to grab. Maybe you only want to create a new variable from the first element in the array. We can do that!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trees&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;spruce&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;elm&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;maple&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;aspen&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;walnut&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;tree1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trees&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;tree1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;spruce&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also skip elements in the array. For instance, to grab the maple tree, we can just provide a comma for each element we want to skip:&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;trees&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;spruce&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;elm&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;maple&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;aspen&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;walnut&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;mapleTree&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trees&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;mapleTree&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;maple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One really cool use for destructuring is when you need to swap 2 elements in an array. Say we wanted to switch the spruce and elm trees positions in the array of trees:&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;trees&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;spruce&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;elm&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;maple&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;aspen&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;walnut&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;trees&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;trees&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;trees&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;trees&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;

&lt;span class="nx"&gt;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;trees&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;elm&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;spruce&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;maple&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;aspen&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;walnut&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;Destructuring can be a little tricky, but the more you see and use it, the easier&lt;br&gt;
it'll be to use in your own code. Be sure to take some time to explore uses in any codebase you're&lt;br&gt;
working in, you might be surprised just how much it's used!&lt;/p&gt;

&lt;h3&gt;
  
  
  To dive deeper into arrays, check out my course &lt;a href="https://speek.design/arrays"&gt;Working with Arrays&lt;/a&gt; 🔥
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>arrays</category>
    </item>
    <item>
      <title>The for loops in JS</title>
      <dc:creator>Jonathan Speek</dc:creator>
      <pubDate>Thu, 25 Mar 2021 08:03:21 +0000</pubDate>
      <link>https://forem.com/jonathanspeek/the-for-loops-in-js-2e8e</link>
      <guid>https://forem.com/jonathanspeek/the-for-loops-in-js-2e8e</guid>
      <description>&lt;p&gt;There are several different ways to loop through elements in an array. Most likely, you will see &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;forEach&lt;/code&gt;, &lt;code&gt;for..in&lt;/code&gt;, and &lt;code&gt;for..of&lt;/code&gt;. These 4 (pseudo pun intended here) are often confused and that's what we are going to fix 💪&lt;/p&gt;

&lt;p&gt;In many older codebases and code examples online, you will see the ubiquitous &lt;code&gt;for&lt;/code&gt; loop used to iterate over an array. The typical setup initializes a variable &lt;code&gt;i&lt;/code&gt; to 0 (because we want to start with the zeroth element). The second statement defines how many times the loop will run, most often you'll iterate over every element in the array - so &lt;code&gt;i &amp;lt; array.length&lt;/code&gt;. And the 3rd statement increasing &lt;code&gt;i&lt;/code&gt; on every pass. This allows us to access each element in the array by its index and perform something.&lt;/p&gt;

&lt;p&gt;Here, we are just logging the score to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In more modern codebases, however, you will see a mix of &lt;code&gt;forEach&lt;/code&gt;, &lt;code&gt;for..in&lt;/code&gt;, and &lt;code&gt;for..of&lt;/code&gt;. The most common scenario you will encounter is that you want to iterate over every element in the array and execute something using that element. So which do you choose?&lt;/p&gt;

&lt;p&gt;Let's start with a more concise version of what the &lt;code&gt;for&lt;/code&gt; loop gives us. With &lt;code&gt;for..of&lt;/code&gt;, we are able to quickly access each element without having to keep track of the index or worry about incrementing/decrementing the index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&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="mi"&gt;82&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;forEach&lt;/code&gt;, you have access to the index of the current element being iterated over, the element value, and the array itself. Sounds great, right? Well it is, and proponents of the &lt;a href="https://eloquentjavascript.net/1st_edition/chapter6.html" rel="noopener noreferrer"&gt;Functional Programming&lt;/a&gt; paradigm greatly prefer this method of looping. &lt;code&gt;forEach&lt;/code&gt; expects a synchronous function, so be aware of that when using &lt;code&gt;async/await&lt;/code&gt; with it. You can’t use &lt;code&gt;await&lt;/code&gt; in the &lt;code&gt;body&lt;/code&gt; of this kind of loop and you can’t leave a &lt;code&gt;forEach&lt;/code&gt; loop early. In &lt;code&gt;for&lt;/code&gt; loops, we can use &lt;code&gt;break&lt;/code&gt;. Do be aware of any mutations you may be making within the loop (if you use a return).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;82&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;for..in&lt;/code&gt; loop is meant to be used with objects, not arrays. So if you use it with an array, you will likely get some unexpected output. This is because &lt;code&gt;for..in&lt;/code&gt; is iterating of the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties" rel="noopener noreferrer"&gt;enumerable properties&lt;/a&gt; of the object (at the end of the day, our arrays are 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&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="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Here's a basic rundown of when to use for..of vs for..in:
&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%2Fwww.speek.design%2Ffor..of-for..in.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%2Fwww.speek.design%2Ffor..of-for..in.png" alt="for loops"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Now that we have a better idea of what the different types of &lt;code&gt;for&lt;/code&gt; loops do, let's dive into some exercises to test our newfound knowledge!&lt;/p&gt;

&lt;p&gt;In your browser, open up the developer tools to the console tab and console log the scores that are less than 90 using the classic &lt;code&gt;for&lt;/code&gt; loop (not &lt;code&gt;for..in&lt;/code&gt; or &lt;code&gt;forEach&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// for() {} loop goes here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, console log the scores that are less than 90 using the &lt;code&gt;forEach&lt;/code&gt; loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// forEach loop goes here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, console log the scores that are less than 90 using the &lt;code&gt;for..of&lt;/code&gt; loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// for..of loop goes here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, console log the index of the scores that are 90 or greater (≥ 90) using the &lt;code&gt;forEach&lt;/code&gt; loop. Hint: the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" rel="noopener noreferrer"&gt;second argument is the index&lt;/a&gt; &lt;code&gt;apples.forEach((apple, index) =&amp;gt; { console.log(index) })&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="c1"&gt;// for loop goes here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Final note on iterating over arrays
&lt;/h3&gt;

&lt;p&gt;Remember when I told you that &lt;code&gt;forEach&lt;/code&gt; is expecting a synchronous function? Well we can also use that to our advantage when we don't want to explicitly iterate over an array's elements one-by-one. For longer running loops, you'll see the benefit of using &lt;code&gt;forEach&lt;/code&gt; vs reaching for &lt;code&gt;for..of&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's take our scores and loop over them using &lt;code&gt;forEach&lt;/code&gt;. If we pretend that we have some longer running code in there using &lt;code&gt;async/await&lt;/code&gt;, you'll notice that the &lt;code&gt;console.log(score)&lt;/code&gt; doesn't wait for it. This can be a useful tool to take advantage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&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;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//fake long running code&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&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;To contrast, &lt;code&gt;for..of&lt;/code&gt; will wait for that longer running code to finish before moving on to our &lt;code&gt;console.log(score)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;81&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&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;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;//fake long running code&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&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;These are basic examples of running in sequence versus running in parallel. If you're needing to run in sequence, reach for &lt;code&gt;for..of&lt;/code&gt; in this case. If you are able to run in parallel (you don't need to wait for that longer running process), try using &lt;code&gt;forEach&lt;/code&gt; instead.&lt;/p&gt;

&lt;p&gt;For more information on the asynchronous version of &lt;code&gt;for..of&lt;/code&gt;, see this post on &lt;a href="https://2ality.com/2016/10/asynchronous-iteration.html#for-await-of" rel="noopener noreferrer"&gt;&lt;code&gt;for await..of&lt;/code&gt;&lt;/a&gt; 👀&lt;/p&gt;

&lt;h3&gt;
  
  
  To dive deeper into arrays, check out my course &lt;a href="https://speek.design/arrays" rel="noopener noreferrer"&gt;Working with Arrays&lt;/a&gt; 🔥
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>arrays</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Getting started with web accessibility</title>
      <dc:creator>Jonathan Speek</dc:creator>
      <pubDate>Tue, 19 Nov 2019 17:00:55 +0000</pubDate>
      <link>https://forem.com/jonathanspeek/getting-started-with-web-accessibility-3f5j</link>
      <guid>https://forem.com/jonathanspeek/getting-started-with-web-accessibility-3f5j</guid>
      <description>&lt;p&gt;All too often, we find ourselves as makers overlooking and undervaluing an essential aspect of the web: accessibility. We spend a lot of time and effort focused on building out features and functionality, but can everyone use those features? &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. –Tim Berners-Lee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Web accessibility isn't about checking some boxes, and it's not something that can be fully learned in a weekend workshop. Accessibility is a skill that is developed with time, experience, and empathy. It's about thinking outside your own experiences to craft solutions that work for everyone. Accessibility isn’t binary, it exists on a spectrum and we want our products to be on the “more accessible than not” end. &lt;/p&gt;

&lt;p&gt;We all have to start somewhere on our learning journey, so my aim is to help you get going with some great resources. &lt;/p&gt;

&lt;h2&gt;
  
  
  Back to basics
&lt;/h2&gt;

&lt;p&gt;Before even addressing accessibility basics, it’s a good idea to reacquaint yourself with &lt;a href="https://guide.freecodecamp.org/html/html5-semantic-elements/"&gt;proper semantic HTML&lt;/a&gt;. Regardless of what framework you’re in, writing good HTML is important (there’s a reason all those tags exist). What are landmarks and what is the benefit of using them? What can you replace your 4,000 &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;‘s with to be more explicit? You’ll often find that semantic HTML makes for more organized and readable code in the long run. &lt;/p&gt;

&lt;h2&gt;
  
  
  Study up
&lt;/h2&gt;

&lt;p&gt;Just as you once approached learning to code in the first place, a great way to learn some accessibility basics is by finding resources in whatever medium you learn best. Here are some great resources that helped me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://abookapart.com/products/accessibility-for-everyone"&gt;Accessibility for Everyone&lt;/a&gt; book by Laura Kalbag&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://abookapart.com/products/design-for-real-life"&gt;Design for Real Life&lt;/a&gt; book by Anil Dash&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.smashingmagazine.com/printed-books/inclusive-components/"&gt;Inclusive Components&lt;/a&gt; book by Heydon Pickering&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.lynda.com/Web-Design-tutorials/Accessibility-Web-Design/606090-2.html"&gt;Accessibility for Web Design&lt;/a&gt; course on Lynda by Derek Featherstone&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/playlist?list=PLNYkxOF6rcICWx0C9LVWWVqvHlYJyqw7g"&gt;A11ycasts&lt;/a&gt; with Rob Dodson on YouTube&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.dev/accessible/"&gt;Google's Web Fundamentals guide on Accessibility&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.udacity.com/course/web-accessibility--ud891"&gt;Web Accessibility&lt;/a&gt; course on Udactiy by Google&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility"&gt;MDN Accessibility docs&lt;/a&gt; by Mozilla&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/WAI/fundamentals/accessibility-intro/"&gt;Accessibility Fundamentals&lt;/a&gt; by W3C&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/WCAG21/"&gt;Web Content Accessibility Guidelines (WCAG) 2.1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You might also find it useful to see some applied accessibility in more digestible contexts. I'd suggest searching for "accessible" on &lt;a href="https://codepen.io"&gt;codepen.io&lt;/a&gt; and playing with some of the examples there. In the same way you've learned programming techniques from looking at other's solutions, you'll find it equally valuable to see various approaches to web accessibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility tooling
&lt;/h2&gt;

&lt;p&gt;Once you have some of the basics of accessibility under your belt, you'll want to grab some handy tools that make your job easier and help build healthy habits. This is not meant to be exhaustive, but these are some tools I use on a day-to-day basis that I've found super helpful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://michelf.ca/projects/sim-daltonism/"&gt;Sim Daltonism&lt;/a&gt; - Mac app that overlays anything on your desktop to give you various color blindness perspectives (this is my favorite app)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://getstark.co/"&gt;Stark&lt;/a&gt; - contrast checker and color blind simulator for Sketch, Figma and Xd&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://funkify.org"&gt;Funkify&lt;/a&gt; - extension to experience the web through the lens of users with different abilities and disabilities&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.hemingwayapp.com/"&gt;Hemingway App&lt;/a&gt; -  for assessing grade level readability of your copy and content&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://chrome.google.com/webstore/detail/high-contrast/djcfdncoelnlbldjfhinnjlhdjlikmph"&gt;High Contrast&lt;/a&gt; extension by Google to help simulate how your app/site responds to Windows High Contrast Mode&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://chrome.google.com/webstore/detail/accessibility-insights-fo/pbjjkligggfmakdaogkfomddhfmpjeni"&gt;Accessibility Insights for Web&lt;/a&gt; - extension by Microsoft with both manual and automated accessibility checks that generates a detailed report (perfect for aiding in an internal audit)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://web.dev/color-contrast/"&gt;Chrome DevTools (checking color contrast)&lt;/a&gt; - DevTools has a way to check color contrast of an element against its background, even supplying a WCAG rating&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://css-tricks.com/throttling-the-network/"&gt;Throttle the network&lt;/a&gt; - in DevTools, you can throttle the network to see how others in emerging countries or remote areas may experience your product&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.applevis.com/guides/beginners-guide-using-macos-voiceover"&gt;VoiceOver&lt;/a&gt; - the built-in screenreader for Mac will help you more clearly understand the importance of semantic HTML&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.nvaccess.org/download/"&gt;NVDA&lt;/a&gt; - a free screenreader for PC (alternative to JAWS)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://webaim.org/resources/contrastchecker/"&gt;Color contrast checker&lt;/a&gt; by WebAIM - a great way to assess contrast ratios and play with values&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/web/tools/lighthouse/"&gt;Lighthouse&lt;/a&gt; by Google - automated tool for improving the quality of web pages (including accessibility)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=eBefjaWud-M"&gt;Firefox Accessibility Inspector&lt;/a&gt; - Jen Simmons walks you through some basics of using &lt;a href="https://hacks.mozilla.org/2019/10/auditing-for-accessibility-problems-with-firefox-developer-tools/"&gt;Firefox's built-in tools&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tl;dr
&lt;/h2&gt;

&lt;p&gt;Building things that consider everyone is our responsibility and should be taken seriously. Familiarize yourself with the basics of web accessibility and apply it in your everyday design and development. As with any skill, you'll get better with practice and experience - soon finding yourself building with an accessibility mindset.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to make your fancy SVG button accessible</title>
      <dc:creator>Jonathan Speek</dc:creator>
      <pubDate>Thu, 23 May 2019 19:16:29 +0000</pubDate>
      <link>https://forem.com/jonathanspeek/how-to-make-your-fancy-svg-button-accessible-3n41</link>
      <guid>https://forem.com/jonathanspeek/how-to-make-your-fancy-svg-button-accessible-3n41</guid>
      <description>&lt;p&gt;You may very well find yourself one day having to build some crazy button a designer dreamed-up. You might start reaching for that good old &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, but easy there big-shifter 🚚  —  let’s try and use that &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; element you’re avoiding 😬&lt;/p&gt;

&lt;p&gt;We’ll start by simply grabbing the code for an SVG icon that we want to use. I quickly made a &lt;a href="https://codepen.io/JonathanSpeek/pen/pQxYqo"&gt;Chemex icon you can use here&lt;/a&gt; (I love me some coffee ☕️). Paste that between a &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; tag in your HTML like so (the SVG code will be pretty lengthy).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WlFPKntb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/xia56rz5uqbuhcd50q2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WlFPKntb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/xia56rz5uqbuhcd50q2d.png" alt="Initial &amp;lt;button&amp;gt; with SVG code inside" width="800" height="249"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We want this button stripped of its default styling, so let’s give the button an “id” and we’ll target it with some CSS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tSq6PCLn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/bwvk0ny8h5gf3560mabj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tSq6PCLn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/bwvk0ny8h5gf3560mabj.png" alt="Strip the default styling of the &amp;lt;button&amp;gt; so we can make it better 💁" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Give the button a good width/height that is larger than our SVG — this will help the visibility of the outline. Speaking of, make sure the contrast ratio between your outline color and the background color passes this. Get rid of that pesky border and background, make sure the cursor is set to pointer.&lt;/p&gt;

&lt;p&gt;At this point, you have a clickable button that, when clicked, shows the default outline your browser has chosen for focus states. Let’s change that and make it better.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7yhPrIHz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/0z1ugwhfiz8oax9la5ps.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7yhPrIHz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/0z1ugwhfiz8oax9la5ps.png" alt="Giving the button some focus 🤓" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now when we click or tab to our button, we get a cool little dashed outline that lets us know where we’re focused.&lt;/p&gt;

&lt;p&gt;We also want to ensure that the SVG itself does not get an outline if clicked. And we want to make certain Firefox doesn’t add its default dotted outline. While we’re at it, we can give the SVG a little hover effect.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jP8kVdaZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/6gvpmbom69llymgergiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jP8kVdaZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/6gvpmbom69llymgergiq.png" alt="Adding our flavorful hover effect 😺" width="800" height="751"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we can get to the cool parts 😎 We don’t want to annoy or confuse our screen reader users with our button. So we need a good short description of what to expect. You would also typically want visual users to have an idea of what it is they’re clicking on as well, for now let’s keep ’em guessing...&lt;/p&gt;

&lt;p&gt;We can easily achieve this by putting a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; element around the text in our button and styling it out of view. Make sure not to set display to “none”, as this will also prevent our screen readers for accessing it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a70t5acv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/87h0yfe65f8nyrxjfnd9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a70t5acv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/87h0yfe65f8nyrxjfnd9.png" alt="Telling our screen reader users what they’re clicking on 💬" width="800" height="537"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, let’s make sure we’ve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hidden the SVG from anyone using assistive technology and&lt;/li&gt;
&lt;li&gt;set the tabindex to “0” so that the browser uses the expected tab order for any keyboard users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i_jj4Pzk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/p5c4lwsspyqrcm3i42dz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i_jj4Pzk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/p5c4lwsspyqrcm3i42dz.png" alt="Setting the proper tab order ⌨️" width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should now have a really accessible button that you can be proud of 💥Besides patting yourself on the back — do it now — going forward you now have some reusable patterns that you can implement that help make the web just a little more accessible 😘&lt;/p&gt;

&lt;p&gt;Here’s a &lt;a href="https://codepen.io/JonathanSpeek/pen/JeRwgp"&gt;link to the CodePen example&lt;/a&gt;, feel free to fork your own copy 🍴&lt;/p&gt;

&lt;p&gt;Thanks for reading. If you have some knowledge to drop on accessibility, be sure to leave a comment!&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>svg</category>
      <category>a11y</category>
    </item>
  </channel>
</rss>
