<?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: Lee</title>
    <description>The latest articles on DEV Community by Lee (@bananabrann).</description>
    <link>https://dev.to/bananabrann</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%2F126712%2F436ada9d-b0f6-4084-84e0-a09abd5cf7db.jpg</url>
      <title>DEV Community: Lee</title>
      <link>https://dev.to/bananabrann</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bananabrann"/>
    <language>en</language>
    <item>
      <title>Stupid Short: Bash's |, &gt;, &gt;&gt;, &lt;, 2&gt;&gt;, 2&gt; Operators</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Sat, 14 Sep 2019 17:18:19 +0000</pubDate>
      <link>https://dev.to/bananabrann/stupid-short-bash-s-2-2-4n1m</link>
      <guid>https://dev.to/bananabrann/stupid-short-bash-s-2-2-4n1m</guid>
      <description>&lt;p&gt;This is meant to be a stupid-short introductory and reference guide for quickly understanding these Bash operators: &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;1&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;1&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;2&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;2&amp;gt;&amp;gt;&lt;/code&gt;. This is primarily done with one sentence and an example.&lt;/p&gt;

&lt;p&gt;This guide assumes...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;... you are using Bash terminal. (OS is not relevant)&lt;/li&gt;
&lt;li&gt;... you are familiar with CLI usage and navigation.&lt;/li&gt;
&lt;li&gt;... you are familiar with the concepts of Bash program arguments/flags/options.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Mostly-Short Explanation of Fundamentals&lt;/li&gt;
&lt;li&gt;Vocab for Stupid-Short List&lt;/li&gt;
&lt;li&gt;Stupid-Short Explanations List&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: For this blog, we will assume we are only writing and reading files.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Mostly-Short Fundamentals &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Admittedly, I never bothered to look up what the &lt;code&gt;|&lt;/code&gt; &lt;code&gt;&amp;gt;&lt;/code&gt; &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; operators do in Linux until well into my programming career. If you've ever followed GitHub's instructions for adding an SSH key to your account, then you've already used are called &lt;strong&gt;Redirect Operators&lt;/strong&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  Fundamentals of Programs
&lt;/h3&gt;

&lt;p&gt;A program has three input and output streams with their corresponding number. It has a standard input (STDIN)(0), standard output (STDOUT)(1), and standard error (STDERR)(2).&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flamacqc2g7epx8g8hkb5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Flamacqc2g7epx8g8hkb5.png" alt="Chart of program I/O streams"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: My beautiful picture is only showing convention. If you build your own program, you can effectively name streams whatever you'd like and stream to whatever output. You don't know that though. If you do, act like you don't and read on.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example: Let's take the good ol' &lt;code&gt;ls&lt;/code&gt;. When you &lt;code&gt;ls&lt;/code&gt; with no error, the input is &lt;code&gt;./&lt;/code&gt; (Bash assumes empty is current directory), the stdout is the list of directories you then see, and the stderr is nothing (Because there's no error to catch).&lt;/p&gt;

&lt;p&gt;Programs stream both stdout and stderr; this is because it's &lt;em&gt;not&lt;/em&gt; "stdout or stderr", it's "stdout &lt;strong&gt;and&lt;/strong&gt; stderr". Running &lt;code&gt;ls presentDir notPresentDir&lt;/code&gt;, you can see both stdout and stderr.&lt;/p&gt;

&lt;p&gt;By default, stdout, stderr, and stdin are all in the terminal. With these redirection operators, we're simply &lt;strong&gt;redirecting those streams elsewhere&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Vocab &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;"program"&lt;/strong&gt;: This is what executables are called in terminal. Every time you &lt;code&gt;cd&lt;/code&gt; or &lt;code&gt;ls&lt;/code&gt;, you're running a program.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;cat&lt;/code&gt;&lt;/strong&gt;: Program that prints the contents of a given file.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;wc -w&lt;/code&gt;&lt;/strong&gt;: Program that outputs the count of words in a file.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pbc&lt;/code&gt;&lt;/strong&gt;: My alias for &lt;code&gt;xclip -selection clipboard&lt;/code&gt;. For Mac folks, this is the exact same thing as &lt;code&gt;pbcopy&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;pbp&lt;/code&gt;&lt;/strong&gt;: My alias for pasting clipboard.&lt;/p&gt;


&lt;h1&gt;
  
  
  Stupid-Short List &lt;a&gt;&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;⭐️ The redirect operators have three numbers correlating with the output: 0 = input, 1 = output, 2 = error. If no number is given, &lt;strong&gt;this defaults to 1&lt;/strong&gt;.&lt;br&gt;
⭐️ If the file does not exist, &lt;strong&gt;these operators create the file.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/strong&gt; Write stdout to given file.
&lt;/h3&gt;

&lt;p&gt;Sends stdout to a given file, instead of printing in the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; list.txt

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;list.txt
lubbock.txt
odessa.txt
baird.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;&lt;/strong&gt; Appends stdout to given file.
&lt;/h3&gt;

&lt;p&gt;Adds stdout to file contents, not replacing file contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Flamingo"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; favorite-birds.txt

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;favorite-birds.txt
Cardinal
Penguin
Flamingo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/strong&gt; Redirects file as stdin
&lt;/h3&gt;

&lt;p&gt;Passes the contents of a file as the stdin.&lt;br&gt;
Example: If we use &lt;code&gt;wc -w book.txt&lt;/code&gt;, the program will output the word count and the filename of book.txt (ex: &lt;code&gt;2394 book.txt&lt;/code&gt;).&lt;br&gt;
If we use &lt;code&gt;wc -w &amp;lt; book.txt&lt;/code&gt; we are "passing in" the contents of book.txt as the input, therefore &lt;code&gt;wc -w &amp;lt; book.txt&lt;/code&gt; would return only the number (&lt;code&gt;2394&lt;/code&gt;), as if we typed the whole thing into terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; book.txt
2394 book.txt

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt; &amp;lt; book.txt
2394
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;2&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Redirect stderr to given file.
&lt;/h3&gt;

&lt;p&gt;If there is an error, redirect the stderr to a file instead of printing in terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls &lt;/span&gt;cuteDogPics 2&amp;gt; example.txt

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;example.txt
&lt;span class="nb"&gt;ls&lt;/span&gt;: cuteDogPics: No such file or directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;2&amp;gt;&amp;gt;&lt;/code&gt;&lt;/strong&gt;: Appends stderr to given file.
&lt;/h3&gt;

&lt;p&gt;Exactly like &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt;, except with stderr.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; ~/Documents/Reports/June2019.xlsx ~/Desktop 2&amp;gt;&amp;gt; ~/error.log

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; ~/error.log
&lt;span class="nb"&gt;cp&lt;/span&gt;: /Users/bananabrann/Reports/January2019.xlsx: No such file or directory
&lt;span class="nb"&gt;cp&lt;/span&gt;: /Users/bananabrann/Reports/March2019.xlsx: No such file or directory
&lt;span class="nb"&gt;cp&lt;/span&gt;: /Users/bananabrann/Reports/June2019.xlsx: No such file or directory

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

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;code&gt;|&lt;/code&gt;&lt;/strong&gt;: Use the stdout as stdin for the next program.
&lt;/h3&gt;

&lt;p&gt;Use the stdout of the program left of the &lt;code&gt;|&lt;/code&gt; as stdin to the program to the right.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt;
buffalo-gap.txt
abilene.txt
clyde.txt
lubbock.txt

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt; | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-2&lt;/span&gt;
buffalo-gap.txt
abilene.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Able to be daisy-chained
&lt;/h3&gt;

&lt;p&gt;Using the &lt;code&gt;|&lt;/code&gt;, we can ultimately chain as many programs as we'd like to achieve the desired result.&lt;br&gt;
In the picture below, we take the stdout of the &lt;code&gt;grep&lt;/code&gt; program and send it as the stdin of &lt;code&gt;head&lt;/code&gt; and its arguments. We then send that stdout to the stdin of &lt;code&gt;tail&lt;/code&gt;, then finally redirect the stdout to guestlist.txt.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl3mekrtpir94xi7dhiun.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl3mekrtpir94xi7dhiun.jpeg" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Hope this helped someone, or sparked someone's interest to play around with these operators and research further on their own!&lt;/p&gt;

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

</description>
      <category>explainlikeimfive</category>
      <category>tutorial</category>
      <category>bash</category>
      <category>linux</category>
    </item>
    <item>
      <title>No Shame, Here's My First React Site</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Sat, 23 Feb 2019 15:36:05 +0000</pubDate>
      <link>https://dev.to/bananabrann/no-shame-heres-my-first-react-site-4i33</link>
      <guid>https://dev.to/bananabrann/no-shame-heres-my-first-react-site-4i33</guid>
      <description>&lt;p&gt;This past week, I worked on building a Would You Rather game with &lt;a href="https://github.com/RendonEls" rel="noopener noreferrer"&gt;@RendonEls&lt;/a&gt;. I learned a lot about React, and definitely feel more comfortable with it after tackling this project.&lt;/p&gt;

&lt;p&gt;However, a lot of times we only see others' highlight reels, so I figured I'd show off (and hide in the corner) my first full-CRUD site using React. No one is born a champion, so it's alright to have a bit of fun and briefly check out my Would You Rather game that isn't so production-ready. So hey, let's have some fun and look at all the things wrong!&lt;/p&gt;




&lt;h2&gt;
  
  
  Landing Page
&lt;/h2&gt;

&lt;p&gt;When you first come on the site, you're presented with the homepage.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd4n8ywgtduka8zaj3ytb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd4n8ywgtduka8zaj3ytb.png" alt="homepage"&gt;&lt;/a&gt;&lt;br&gt;
You have the ability to play, view stats, or go to options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Playing the Game
&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdp488oi90r5mk9qsx69s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdp488oi90r5mk9qsx69s.png" alt="play"&gt;&lt;/a&gt;&lt;br&gt;
Here is the play screen. Right now, the game isn't even playable, haha! But hey, it displays two random questions!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No way to select a question.&lt;/li&gt;
&lt;li&gt;No next button.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Options - Create
&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8ps9p1erkjexnkrkopjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8ps9p1erkjexnkrkopjd.png" alt="create"&gt;&lt;/a&gt;&lt;br&gt;
After going into options, you can create a question. This part of the site is probably the part that looks the best, but is also the simplest.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pressing submit neither redirects nor refreshes.&lt;/li&gt;
&lt;li&gt;Navigating away, after submitting, does not show your question anywhere. You have to refresh manually no matter what page you go to. 😅&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Options - Edit
&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8igjw1vpno1adn81ets9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8igjw1vpno1adn81ets9.png" alt="edit"&gt;&lt;/a&gt;&lt;br&gt;
Ah, the edit page. The bane of our existence, both on the back-end and front-end. In the end, it ended up being like 40 lines of code. This took us around 24 working hours to complete, but it works!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clicking delete also immediately deletes the question, without refresh! 😃&lt;/li&gt;
&lt;li&gt;Adding enough questions so it goes past the footer &lt;strong&gt;destroys&lt;/strong&gt; the footer.&lt;/li&gt;
&lt;/ul&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftky92gx6zxvp8p5m1kp8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftky92gx6zxvp8p5m1kp8.png" alt="edit with inserts"&gt;&lt;/a&gt;&lt;br&gt;
... And then you press edit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clicking edit on one will drop the boxes down for all.&lt;/li&gt;
&lt;li&gt;Clicking submit updates them immediately within state, and doesn't refresh! 😃😃😃&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;That's it! I hope this sadistically inspires someone, or at least gets a half-smile from some veteran coders. May your bugs be short, and Happy Coding!&lt;/p&gt;

&lt;p&gt;Deployed website:&lt;br&gt;
&lt;a href="http://dirty-fan.surge.sh/" rel="noopener noreferrer"&gt;http://dirty-fan.surge.sh/&lt;/a&gt;&lt;br&gt;
Front-end Repo:&lt;br&gt;
&lt;a href="https://github.com/bananabrann/would-you-rather-frontend" rel="noopener noreferrer"&gt;https://github.com/bananabrann/would-you-rather-frontend&lt;/a&gt;&lt;br&gt;
Back-end Repo: &lt;br&gt;
&lt;a href="https://github.com/RendonEls/would-you-rather-backend" rel="noopener noreferrer"&gt;https://github.com/RendonEls/would-you-rather-backend&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;P.S. If you're feeling really ambitious, share us your first site ever!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/pbrann?trk=profile-badge" rel="noopener noreferrer"&gt;Pierson L. Brannan&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>react</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Coding, A Blue Collar Job?</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Mon, 18 Feb 2019 02:16:49 +0000</pubDate>
      <link>https://dev.to/bananabrann/coding-a-blue-collar-job-pfn</link>
      <guid>https://dev.to/bananabrann/coding-a-blue-collar-job-pfn</guid>
      <description>&lt;p&gt;Raising chickens in a rural area was something a part of my daily life. Moving into the city and jumping into coding, I have to admit: The same determination and hard work that drives rural Americans to success is the exact same I've seen in successful developers. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you’ve never heard of this term, jobs that require manual labor are often called “blue collar,” and &lt;a href="https://slate.com/business/2012/05/blue-collar-white-collar-why-do-we-use-these-terms.html"&gt;it’s been called this since 1924.&lt;/a&gt; These jobs can mainly be broken down into two categories: &lt;em&gt;Unskilled&lt;/em&gt;, such as mining and warehouse, and &lt;em&gt;Skilled&lt;/em&gt;, such as electricians and welders. Unskilled and skilled work blue-collar has been a major driving engine in the U.S. economy, and skilled blue-collar spurred the growth of the middle class.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The mindset we use when approaching a certain skill greatly impacts how fast or slow we might grow, or even the quality of the final output of that product. This mindset can be of efficiency, growth, quality, or whatever value that might drive you and that trade. I draw the resemblance with blue-collar work and coding because they both act on a tangible, physical output as opposed intellectual or efficiency outputs of the work from that such as lawyers and accountants.&lt;/p&gt;

&lt;p&gt;The reasoning can go further when evaluating similarities in the market of coding and that of blue-collar work. &lt;a href="https://www.montgomeryadvertiser.com/story/news/2018/05/25/retiring-boomers-leave-blue-collar-void/633181002/"&gt;With our older generations retiring&lt;/a&gt;, demand for skilled labor is at an all-time high, and companies are telling us they're willing to compensate. Let's look at plumbers, where &lt;a href="https://www.nytimes.com/2014/03/25/your-money/sweet-smell-of-money-for-plumbers.html"&gt;the average in Chicago and NYC is now $70,000 a year&lt;/a&gt;. For more experienced plumbers, that number reportedly &lt;a href="https://nypost.com/2016/08/03/city-plumber-made-more-in-ot-than-de-blasios-total-salary/"&gt;goes as high as $200,000&lt;/a&gt;! I'm sure you've heard of the same thing happening with developers. Bashing our head against our keyboard is grit not everyone is set up for, and difficult to place competent and skillful developers into the workforce. Developers with little to no experience are landing $70,000/yr or more jobs, and the sky is becoming the limit with more senior and experienced positions &lt;a href="https://money.usnews.com/careers/best-jobs/software-developer/salary"&gt;raking-in well over six digits nationally&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These stats do not mean there's a giant pot of gold for everyone that steps into software development. Like in blue-collar jobs, to reap the fruit of your own labor your skills and improvement must be accountable by only yourself. &lt;/p&gt;

&lt;p&gt;The mindset that makes successful plumbers in NYC and Chicago is near identical of that of the developer, and I believe there are things to learn in improving our code skills from the lessons of those who use their hands.&lt;/p&gt;




&lt;h4&gt;
  
  
  Do you think of coding as blue-collar? Why or why not?
&lt;/h4&gt;

&lt;p&gt;Thanks for reading, and happy coding!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I Ask: Do people actually say "MERN-stack?"</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Tue, 29 Jan 2019 21:48:59 +0000</pubDate>
      <link>https://dev.to/bananabrann/i-ask-do-people-actually-say-mern-stack-3icc</link>
      <guid>https://dev.to/bananabrann/i-ask-do-people-actually-say-mern-stack-3icc</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Have you ever heard the term "MERN-stack" used?&lt;/li&gt;
&lt;li&gt;From your experience, would the majority of coders around you understand what that entails to someone's coding tools if they say they're a "MERN-stack developer?" What do you think about this?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;MERN refers to Mongo, Express, React, and Node.&lt;/strong&gt; It's a term I've started hearing early this month, and thought nothing of it other than a cool acronym to describe these toolsets. Then, I started hearing it called the "MERN-stack," and one or two "MERN-stack developers" and January passed on.&lt;/p&gt;

&lt;p&gt;This is pure curiosity, and I'd be interested in reading your replies.&lt;/p&gt;

&lt;p&gt;Thanks for your answers, and Happy Coding!&lt;br&gt;
~bananabrann&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>discuss</category>
      <category>mern</category>
    </item>
    <item>
      <title>Express Routing Walkthrough For Noobs: Pretend You're A Computer</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Fri, 25 Jan 2019 01:25:06 +0000</pubDate>
      <link>https://dev.to/bananabrann/express-routing-for-noobs-pretend-youre-a-computer-walkthrough-1ma4</link>
      <guid>https://dev.to/bananabrann/express-routing-for-noobs-pretend-youre-a-computer-walkthrough-1ma4</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;CONTENTS&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introductory&lt;/li&gt;
&lt;li&gt;What's MVC?&lt;/li&gt;
&lt;li&gt;What Happens When You Visit a Webpage&lt;/li&gt;
&lt;li&gt;Become the Computer: A Roadmap, Routes&lt;/li&gt;
&lt;li&gt;Become the Computer: A Roadmap, Controller Example&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  This Blog Contains:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Visualization of routing within Express&lt;/li&gt;
&lt;li&gt;Basic, basic review of MVC&lt;/li&gt;
&lt;li&gt;Does NOT contain explanation of Models or Controllers&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;INTRODUCTORY&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;So I’m learning how to code, and I’m holding on to the handlebars —get it?— for dear life. There’s so many “things,” with so much “stuff.” Along the way, my love of knowing what all the little files in my folders do is being blown out the window and swept away into the gutter to fall into the ocean to only be  eaten by a shark. That shark is currently Express, Node, Handlebars, and somehow launching it at the moon hoping to catch the internet.&lt;/p&gt;

&lt;p&gt;The biggest, baddest shark in the pond is Express. In particular, navigating between the files via routing. I'm starting to conquer the inner-understandings of it, and the best way that has helped me is to pretend I'm a computer. Beep boop!&lt;/p&gt;

&lt;p&gt;This is very in the weeds when you're reading it, and is best explained in 10 seconds in-person, but this has been a very instrumental mindset in understanding how routes work within Express.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What's MVC?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;MVC stands for Model, View, Controller. It's a way to organize our files within a project. We separate the files by what they do.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model, what stuff is. &lt;/li&gt;
&lt;li&gt;View, what stuff looks like.&lt;/li&gt;
&lt;li&gt;Controller, what the stuff does.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no program to install, no uniform name, no nothin'. It's simply &lt;strong&gt;just a way we name and place a file&lt;/strong&gt; for our own personal zen.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;What Happens When You Visit A Website?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When you open your browser and type in a website, your browser submits what is called a GET request. This is one of four basic request types for data. With that GET request, the server of the website is "listening" to where you go. Because you decided to organize your files by MVC, our router is now responsible to linking your files together so that the correct response is served to the client!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Become A Computer: A Roadmap, Routes&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The single-most thing that has helped me patch all of (mostly) Express, is to think about if I was a computer on the server-side. This is the fun part!&lt;/p&gt;

&lt;p&gt;For reference in this example of computer roleplay, our relevant file structure will look this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
├── controllers
│   ├── application.js
│   ├── birds.js
│   ├── index.js
│   └── lizards.js
├── index.js
├── models
│   ├── Bird.js
│   ├── Lizard.js
├── routes
│   ├── birds.js
│   ├── index.js
│   └── lizards.js
└── views
    ├── birdsflying.hbs
    └── lizardscrawling.hbs

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Your file structure of names, folders, conventions, might all be different. This is not a standard pattern, your routes can link anything to anything!&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Our Journey Begins, Setting Up with index.js
&lt;/h3&gt;

&lt;p&gt;As a highly advanced technological marvel, you need to be told a few things before you're ready to work. &lt;em&gt;Who and what am I?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To do this, our index.js, with the main project folder, answers most of those questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember, we're the server!&lt;/strong&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Cool, I'm going to be using Express today. I hope my user didn't forget to npm install express me!&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hbs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hbs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Looks like I'm also using Handlebars.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Nice! When I see "app," I'm going to be calling the function named express.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./routes/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Uh-huh... I see that when I call the variable "routes," I'm going to be shooting it over to the routes folder!&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;public&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Looks like I'll be serving "static" files today, such as CSS and JavaScript.&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;view engine&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;hbs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Oh right, I'm supposed to use hbs when I go to display things.&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&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="nx"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// When I get something, I'll call the "routes" variable. Good thing I defined it above!&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./routes/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// I need the routes/index.js file, OR ELSE I QUIT. That'll show the user!&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;server is running&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="c1"&gt;// Oh cool, I'm listening on port 3000.&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Now that we know who we are, we're all ears for the user input!&lt;/p&gt;




&lt;h3&gt;
  
  
  Ground Zero, index.js
&lt;/h3&gt;

&lt;p&gt;We have a request! Someone visited Port 3000, now we're ready to role! This is a GET request, so all we need to do is show the user something. We know this, because we're born with it! (We know these things from Express and JavaScript built-in)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let's roll down our index.js file. At first, we just know who we are. &lt;/li&gt;
&lt;li&gt;Alright. The user is requesting the the page called pigeon &lt;code&gt;/birds/pigeon&lt;/code&gt;.  Whoah! One of my commands activates when I'm requested for &lt;code&gt;/&lt;/code&gt;! &lt;code&gt;app.use("/", routes);&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;app.use("/", routes);&lt;/code&gt; So based on this, I call &lt;code&gt;routes&lt;/code&gt;. We defined it earlier, with &lt;code&gt;const routes = require("./routes/index.js");&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Nice! That &lt;code&gt;require&lt;/code&gt; means I go to that file now, and keep going!&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Journey to the Routes Folder, routers/index.js
&lt;/h3&gt;

&lt;p&gt;Specified as earlier with &lt;code&gt;app.use("/", routes);&lt;/code&gt; referencing &lt;code&gt;const routes = require("./routes/index.js");&lt;/code&gt;, our adventure to find out what happens when our user visits /pigeon has first taken us to the index.js file within routes.&lt;/p&gt;

&lt;p&gt;The routers/index.js file is basically responsible for funneling all the other routes together.&lt;/p&gt;

&lt;p&gt;*Why? Future-proof our route so that we can simply refer to router/index.js instead of linking the routes directly.&lt;/p&gt;

&lt;p&gt;We, the computer, read top to bottom. Using &lt;code&gt;//&lt;/code&gt;, let's follow our path and see where our files want us to go.&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;// Ahh, the routes index.js file! Good times here. Let's take a look... I'm looking to see where I should go for /birds/pigeon.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Looks like I'm still using Express.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Okay, I'm using Express's Router method for the following. I need this because it's a part of the framework.&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&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="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./application.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// If user requests homepage, shoot them to ./application.js. Remember, . is current directory, but this isn't what we're looking for!&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/lizards&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./lizards&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// If user requests /lizards, we will send them to lizards.js. Nope!&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/birds&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./birds&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// If user requests /birds, we wil send them to birds.js. This is what we want, let's go!&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stepping into routes/birds.js
&lt;/h3&gt;

&lt;p&gt;Yes! We're here, in routes/birds.js! Alright, what's in here?&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;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&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;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Hey, I remember these!&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;birdController&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../controllers/birds&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Huh. Alright, we have a variable called birdController, and it requires us to go to the controllers/birds.js file. We don't need to mark it with `.js`, because Express framework tells us to. Remember, `..` goes up a directory and we're currently in routes!&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&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="nx"&gt;birdController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;show&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Hey, this is our path, birds/, but we're looking for /birds/pigeon. We just see / and not /birds because we're in /birds. Think of it as changing directories. So... Nope, not our stop!&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/pigeon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birdController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// This is it! This is /birds/pigeon! But there's one thing... I have a GET request, not a POST request. So this is the correct path, but not the correct action. Let's keep looking...&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/pigeon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;birdController&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;show&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// YES! Here is our GET request for /birds/pigeons. Let's see... It wants us to execute the .show method on birdController. What's birdController? Oh, right, we defined it up above! We need to travel to ../controllers/birds.js&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// How we travel! Without this, we'd be trapped here.&lt;/span&gt;


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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Become A Computer: A Roadmap, Controller Example&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Arriving At the Magic, controllers/birds.js
&lt;/h3&gt;

&lt;p&gt;We made it! Controllers are where the action is. Think of controllers are normal JavaScript. This is what the guts are, and that normal JavaScript drives it. Look how the models come in to play now, this is where it all happens, lead to you dynamically thanks to routes!&lt;/p&gt;

&lt;p&gt;Notice the method from before when birdController called &lt;code&gt;birdController.show&lt;/code&gt;, &lt;code&gt;.show&lt;/code&gt; being the method.&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;Bird&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../models/Bird&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;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../models/User&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;create&lt;/span&gt;&lt;span class="p"&gt;:&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="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="nx"&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;This is what we weren't looking for!&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;show&lt;/span&gt;&lt;span class="p"&gt;:&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="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="nx"&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;This is what we were looking for!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// The code here would be executed with birdController.show.&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;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thinking about how the computer reads the code tremendously helped me understand why the code is written the way it is. I really hope it helped you visualize it and understand it too!&lt;/p&gt;

&lt;p&gt;Find it helpful? Do I have any errors? Have questions? Have feedback? Let me know!&lt;/p&gt;

&lt;p&gt;Thanks for reading, and Happy Coding!&lt;br&gt;
~bananabrann&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>express</category>
      <category>productivity</category>
    </item>
    <item>
      <title>.includes For Noobs</title>
      <dc:creator>Lee</dc:creator>
      <pubDate>Fri, 11 Jan 2019 21:03:46 +0000</pubDate>
      <link>https://dev.to/bananabrann/includes-for-noobs-41cc</link>
      <guid>https://dev.to/bananabrann/includes-for-noobs-41cc</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;CONTENTS&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Crash-Landing&lt;/li&gt;
&lt;li&gt;Syntax&lt;/li&gt;
&lt;li&gt;Search Within Arrays&lt;/li&gt;
&lt;li&gt;Tell It When To Start! (Index, and Indexing Negatives)&lt;/li&gt;
&lt;li&gt;Examples&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;CRASH-LANDING&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;del&gt;Peer into the soul of JavaScript and interrogate what the meaning of code is&lt;/del&gt; &lt;code&gt;.include&lt;/code&gt; is a JavaScript method that searches for whatever you pass in it, wherever you tell it to search. It then returns true or false based on if it found what you were searching for. It is a very simple, but powerful method. For us beginners (me and you!) we'll just be looking at the syntax and attaching to array variables.&lt;/p&gt;

&lt;h5&gt;
  
  
  QUICK NOTES
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;You cannot search for multiple items at once with &lt;code&gt;.includes&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;SYNTAX&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The syntax for &lt;code&gt;.includes&lt;/code&gt; is &lt;code&gt;.includes(value, i)&lt;/code&gt;, where &lt;code&gt;value&lt;/code&gt; is what we're searching for, can be an integer or string, and &lt;code&gt;i&lt;/code&gt; is where we're starting the search. Remember JavaScript starts at 0! &lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;SEARCHING WITHIN ARRAYS&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's say we have an array of our moral character, and we want to know if our array contains certain items. With &lt;code&gt;.includes&lt;/code&gt;, we can easily do this! Let's take a look.&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;morals&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;honor&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;courage&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;justice&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;yourself&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;We're trying to find some courage to continue tackling JavaScript, so let's use &lt;code&gt;.includes&lt;/code&gt; to see if &lt;code&gt;morals&lt;/code&gt; has our courage!&lt;br&gt;
To do this on arrays, we simply call the array and place the syntax of &lt;code&gt;.includes&lt;/code&gt; after it, as such:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;// is the computer's response. If you want to see it, don't forget the &lt;code&gt;console.log&lt;/code&gt;&lt;/em&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;morals&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;honor&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;courage&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;justice&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;yourself&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;morals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;courage&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;morals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;yourself&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;morals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;funny&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also pass in integers instead of strings!&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;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;44&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;55&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;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// true&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;numbers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you would like to play with these examples, &lt;a href="https://codepen.io/starbran/pen/MZGNrK"&gt;check out this CodePen!&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;TELL IT WHEN TO START&lt;/strong&gt;
&lt;/h3&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;(INDEX AND NEGATIVE INDEX)&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Now that we have the basics of &lt;code&gt;.includes&lt;/code&gt;, let's look that that second thing &lt;code&gt;.includes&lt;/code&gt; can take. Let's review syntax:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Earlier, we were substituting things into the &lt;code&gt;value&lt;/code&gt; portion, now we will be substituting something in for &lt;code&gt;i&lt;/code&gt;, or the index. For the &lt;code&gt;.includes&lt;/code&gt; method, this means where the computer will &lt;em&gt;start&lt;/em&gt; looking for the number.&lt;/p&gt;

&lt;p&gt;Check out this code:&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;cities&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;Dallas&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;Miami&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;New York City&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;Seattle&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;When we just pass in a string to search for, as we did in the section previous, the computer defaults to 0 -- start at the beginning.&lt;br&gt;
Placing in a number, remembeirng that JavaScript starts at 0, we can tell JavaScript when to searching for it. If a value is within the array, but before the index, it will return false because of this.&lt;/p&gt;

&lt;p&gt;Notice the changes in output:&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;cities&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;Dallas&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;Miami&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;New York City&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;Seattle&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;cities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dallas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;cities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dallas&lt;/span&gt;&lt;span class="dl"&gt;"&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="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;cities&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dallas&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty simple, right? Good! Now let's do the final thing with &lt;code&gt;.includes&lt;/code&gt;... Negative indexes! Woo!&lt;/p&gt;

&lt;p&gt;Negative indexes act the same as indexes, but start from the end and work forward. When counting from the back, the 0 is &lt;em&gt;not&lt;/em&gt; the first digit, contrary to regular JavaScript number counting. So in an array of &lt;code&gt;[1, 2, 3]&lt;/code&gt; the 1 is an index of -3.&lt;/p&gt;

&lt;p&gt;Let's see it under the microscope:&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;people&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;Mike&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;Jebs&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;Sarah&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;Gary&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;Phil&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;Merilyn&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;Macy&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;Stacy&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;Hacy&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;Lacy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lacy&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// true. JS starts its search at Hacy&lt;/span&gt;
&lt;span class="nx"&gt;people&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Merilyn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// false. JS starts its search at Macy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Congratulations, you now understand this simple yet powerful little method! Go out into the world, and fix all its problems using &lt;code&gt;.includes&lt;/code&gt; now.&lt;/p&gt;

&lt;p&gt;Found this blog helpful? Didn't like it? Let me know!&lt;/p&gt;

&lt;p&gt;Thanks, and Happy Coding!&lt;br&gt;
~bananabrann&lt;/p&gt;

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