<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kevin Neyer on Medium]]></title>
        <description><![CDATA[Stories by Kevin Neyer on Medium]]></description>
        <link>https://medium.com/@kevinneyer?source=rss-34fd22c9ab6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7OtL2EaA8cVQ92HDl2w-FQ.jpeg</url>
            <title>Stories by Kevin Neyer on Medium</title>
            <link>https://medium.com/@kevinneyer?source=rss-34fd22c9ab6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:04:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kevinneyer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Power of the Early Return]]></title>
            <link>https://kevinneyer.medium.com/the-power-of-the-early-return-2f4126b0f70e?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f4126b0f70e</guid>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Wed, 15 Apr 2026 18:17:27 GMT</pubDate>
            <atom:updated>2026-04-15T18:17:27.310Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rW6lNFGDLS9fA-CZ" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Often times when developing, we need to perform a function or operation based on the presence, or lack there of, of data. For example, a user writes a review of a product. In this case, we’d most likely want to check for the presence of a current or logged in user and the content of the review (review text, star rating, etc.). Maybe we’re working in the backend and need to verify data before sending to the frontend. Or, maybe we’re about to dynamically update the frontend based on clicking a “Submit Review” button. While these examples are slightly different, there is an underlying theme — certain data needs to exist in order for the operations to be error prone.</p><p>Here in lies the early return! Let’s say there’s a function called submitReview that is given two arguments: a currentUser and reviewContent. Should the user or review content not exist, we’d want to be able gracefully handle the issue before a bug or system error occurs. If I’ve learned anything over the years, contending for any edge case and pessimistically developing is always a good thing. As a bare bones example, we could do a check to ensure these values are present before moving forward with any logic.</p><pre>const submitReview = (currentUser: userInterface, reviewContent: string): void =&gt; {<br>    if (!currentUser || !reviewContent) {<br>        alert(&#39;Some message here...&#39;);<br>        return;<br>    }<br><br>   // This is where the function logic would continue.<br>};</pre><p>The early return is beneficial because it is a saver on time and operation use. By returning early, we don’t subject our app to running any performative operations, thus reducing run time and performance load.</p><p>This was one of the first ‘tricks’ I learned in the beginning of my career, and I’ve really stuck to it since. Exiting early, should some condition(s) not be met, save us time, operational load, and even potential miscues with the DB (eg. sending the database a review with no associated user). In addition, it can avoid potentially messy if/else if/else blocks.</p><p>Next time you’re in a specific conditional situation, try giving the early return a shot, and I hope it works for you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f4126b0f70e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The While Loop]]></title>
            <link>https://kevinneyer.medium.com/the-while-loop-abb67c73e573?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/abb67c73e573</guid>
            <category><![CDATA[while-loop]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Tue, 09 Feb 2021 16:16:28 GMT</pubDate>
            <atom:updated>2021-02-09T16:16:55.327Z</atom:updated>
            <content:encoded><![CDATA[<p>How I used one to solve an actual life question</p><h3>Introduction</h3><p>Being in software engineering, specifically the job search, one is inundated with algorithmic problems. While there are many great tools out there for practicing, most of the problems aren’t super prevalent in everyday life. Meaning, those specific problems would never happen to me. There could be many reasons for my thinking this, primarily, my exposure to the actual engineering work place is very low, and these types of things haven’t been my norm. Or, I’ve never needed to reverse a string or find valid parenthesis in real life.</p><p>Don’t get me wrong. I understand that most of these problems are very much specific to working with data in a way that would never happen in real life. But, this is the reason why I was so surprised to be able to use a while loop to solve a real world question.</p><h3>The Set Up</h3><p>I was talking to a friend, and she asked me “If I make x amount of money now, and I get an annual raise of y percent, how many years will it take for me to make z amount?”</p><p>I thought, <em>that’s kind of a lot of math to do</em>, but then realized, I could write a loop to solve this! Since I knew I wanted to solve a problem based on a condition being true rather than a set amount of times, I thought the while loop would be my jam. For more information on the while loop, check out the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while">MDN </a>docs.</p><h3>The Execution</h3><p>The problem: given a starting salary and an annual 1.5% raise, how many years will it be before a new desired salary is reached?</p><p>The first thing I did was create a function and declare the variables for current and desired salary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YNVXF90Y5NwW457s1rzYww.png" /><figcaption>Started Function</figcaption></figure><p>Next, add in the meat and potatoes while loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z08kZPuPkRO4eskftYk13g.png" /><figcaption>The While Loop</figcaption></figure><p>And, to top it off, return the years variable to produce the answer. Putting the function in the console should reveal the answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pxevKUZfz4tlUqVSdZF5UQ.png" /></figure><h3>Conclusion</h3><p>There are everyday uses for these types of coding resources/tools. If we keep our ears and eyes open, we might just find a way to use our skillset to help solve some very real and relevant problems!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abb67c73e573" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[So, You’ve Deployed a Project?]]></title>
            <link>https://kevinneyer.medium.com/so-youve-deployed-a-project-e2aa70367e86?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2aa70367e86</guid>
            <category><![CDATA[netlify]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 20:37:33 GMT</pubDate>
            <atom:updated>2021-01-28T20:37:33.685Z</atom:updated>
            <content:encoded><![CDATA[<p>Congrats! Now what?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3og0IAQG2BtR13joe4%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3og0IAQG2BtR13joe4%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3og0IAQG2BtR13joe4%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="241" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7b72125e4344b7e768f607b3a7a99ad/href">https://medium.com/media/f7b72125e4344b7e768f607b3a7a99ad/href</a></iframe><h3>Introduction</h3><p>One of the major accomplishments a software engineer or web developer can achieve is finishing and hosting and deploying a project. Whether this be on the job or for personal pleasure, this is no small feat. The amount of time, energy, and planning needed is is not something to brush aside.</p><p>Now that a project is live, there’s one thing to consider: how to add updates or make changes to the existing project. Larger scale projects, especially for the workplace, might use tools like <a href="https://kubernetes.io/">Kubernetes</a> or <a href="https://www.docker.com/">Docker</a>. But for this article, I want to address tools that are more in line with smaller/personal style projects — Firebase and Netlify.</p><h3>Some Background</h3><p>When I went to deploy my first ever project, my portfolio site, a lot of my peers from my bootcamp cohort, who were also deploying their sites, were using <a href="https://firebase.google.com/">Firebase</a>. Since this seemed like a logical choice, given my site needs, I went about hosting and deploying through Firebase. The documentation is super easy to follow and set up can be done directly through the project directory via the command line. Pretty nice, right? No complaints, everything was up and running a-okay.</p><p>For a recent project, I decided to branch out and use <a href="https://www.netlify.com/">Netlify</a>. While similar, one of the major benefits of Netlify is projects can be connected to Netlify via the project’s GitHub repository. Really simple, right? Select the desired repo to connect, follow the instructions, and bam — it’s up and running.</p><h3>Making Updates</h3><p>Now, for the meat and potatoes of this article — how to update the site.</p><h4>Netlify</h4><p>If the project is deployed via the GitHub repo, as described above, updates are very simple. Any changes that are pushed to main branch(or whichever branch was selected to be deployed), will be automatically updated. That’s it! Easy peasy. As a preventative measure, always be sure to test code before deploying, and make sure you’re working in and pushing to the correct branch!</p><h4>Firebase</h4><p>While incorporating a few more steps, updating a project with Firebase is still straight forward. Again, once all changes have been tested and any sort of version control changes updated, simply add this command via CLI in your project directory.</p><pre>$ firebase deploy --only hosting</pre><p>And, voilà! It’s updated. If using Firebase, I highly recommend checking out this <a href="https://firebase.google.com/docs/hosting/test-preview-deploy">article</a> first.</p><h3>Conclusion</h3><p>Firebase and Netlify are great and easy resources for getting a project off the ground and deployed. And, not to forget, also free. Keeping everything updated is a breeze given how seamlessly these programs were created and designed. Using the above steps, and also, ALWAYS using the documentation, will help your projects always be in tip top shape.</p><p>As a side note, <a href="https://pages.github.com/">GitHub Pages</a> is also a great, free resource for deploying projects straight from a repository.</p><p>Check these out, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2aa70367e86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrow Functions]]></title>
            <link>https://kevinneyer.medium.com/arrow-functions-d5c311265eef?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5c311265eef</guid>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[functions-in-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Fri, 22 Jan 2021 19:52:47 GMT</pubDate>
            <atom:updated>2021-01-22T19:52:47.612Z</atom:updated>
            <content:encoded><![CDATA[<p>ES6 Syntactic Sugar and Practical Uses</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1kb6uKnZsH03SjnF" /><figcaption><a href="https://unsplash.com/@jannerboy62?utm_source=medium&amp;utm_medium=referral">Nick Fewings</a> via <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>With the release of JavaScript ES6 came the introduction of arrow functions. Arrow functions are a concise, syntactically sweet variation on the traditional function expression. While it has its pros, it also has some cons. Let’s take a look!</p><h3>Overview</h3><p>A traditional function expression looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*9wy61UKR6Eo9WRRPliIjSg.png" /><figcaption>Console of Function Expression</figcaption></figure><p>The snazzy arrow function would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*0o74qeVqdrrGM9m0Ka0vBw.png" /><figcaption>Console of Arrow Function</figcaption></figure><p>Notice how this can be nicely compacted into a one line statement. Pretty cool, huh?</p><h3>Syntax and Guidelines</h3><p>If you’re already hip with arrow functions, you might have noticed that the above example is actually an abbreviated version of an arrow function. A more typical arrow function would look like this:</p><pre>addNumsArrow = (num1, num2) =&gt; {<br>    return num1 + num2<br>}</pre><p>If the function has only one statement, and the statement returns a value, you can remove the brackets and the return keyword — like in the earlier example. Other guidelines are as follows:</p><pre>// No arguments === blank parenthesis <br>sayHi = () =&gt; { <br>  return &#39;Hello World&#39; <br>}</pre><pre>// One argument === parenthesis optional<br>sayHiName = name =&gt; {<br>   return `Hi, ${name}`<br>}<br>// or<br>sayHiName = (name) =&gt; { <br>    return `Hi, ${name}`<br>}</pre><pre>// Multiple arguments === parenthesis required<br>sayHiWithDay = (name, day) =&gt; {<br>    return `Hi, ${name}. Happy ${day}!`<br>}</pre><pre>// NOTE: all of the above could be implemented as one liners.</pre><pre>// If the function has multiple lines of code, curly brackets and a return statement are required<br>sayHiName = (name) =&gt; {<br>    if(!name){<br>        return &#39;Hi! Nice to meet you!&#39;<br>    } else<br>    return `Hi, ${name}. Nice to meet you!`<br>}</pre><h3>This and Scoping</h3><p>The handling of <strong>this</strong>in arrow functions is slightly different. As per the MDN documentation:</p><blockquote>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call">call</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply">apply</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind">bind </a>methods are <strong>NOT suitable</strong> for Arrow functions -- as they were designed to allow methods to execute within different scopes -- because <strong>Arrow functions establish &quot;this&quot; based on the scope the Arrow function is defined within.</strong></blockquote><p>Because of this, arrow functions have a benefit. Again, from MDN:</p><blockquote>Perhaps the greatest benefit of using Arrow functions is with DOM-level methods (setTimeout, setInterval, addEventListener) that usually require some kind of closure, call, apply or bind to ensure the function executed in the proper scope.</blockquote><h3>Conclusion</h3><p>Arrow functions are a great tool for helping keep code neat and concise. The main difference between regular function expressions and arrow functions is in how it defines <strong>this </strong>and handles scope. Arrow functions also do not contain “class like” properties(ie. can’t be used as constructors and don’t have a property object). Because of this, be aware of how, when, and where functions are used and called to determine whether or not an arrow function is appropriate. Reference MDN for learning more on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">arrow functions</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function">function expression</a>, and <a href="https://developer.mozilla.org/en-US/docs/Glossary/Scope">scope</a>. Thanks for reading, and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5c311265eef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[localStorage]]></title>
            <link>https://kevinneyer.medium.com/localstorage-455639017ab3?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/455639017ab3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-storage]]></category>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Sat, 16 Jan 2021 22:59:33 GMT</pubDate>
            <atom:updated>2021-01-16T22:59:33.025Z</atom:updated>
            <content:encoded><![CDATA[<p>Using JavaScript to implement the Web Storage API</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FZFuwwNQkNnI7Af9Lae%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FZFuwwNQkNnI7Af9Lae%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FZFuwwNQkNnI7Af9Lae%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/48008dd9e0346d56e409852b12e6a798/href">https://medium.com/media/48008dd9e0346d56e409852b12e6a798/href</a></iframe><h3>Introduction</h3><p>The last few weeks, I’ve been working on a code challenge that was required for an internship application. The challenge was to create a webpage that helped manage nominations for an award show. Users could search a database and nominate their favorite movies they feel should be up for nomination. When they’ve selected 5 nominees, they should be notified they’re finished.</p><p>After achieving the required deliverables, it was suggested to jazz it up a bit and add additional features or styling that best showcased our passions and skills. They gave a few for inspiration. One of which was saving the nominations if a user left the page.</p><p>I had implemented some additional features and styled how I saw fit. I had some time before the application deadline, so I thought it would be cool to figure out how to save the nominations list. Since this was a front-end application(the data base had been provided and all that was needed was an API key), and there were no auth or login features required, I was only working with my React app. My initial thought was, <em>“I can only think of having these stored in a database that’s then called upon during page reopens or reloads”</em>. I knew this was way out of bounds, giving the circumstances. After about a day racking my brain, it naturally occurred to me — <em>“Can I use localStorage?”</em>. I had only used localStorage when implementing auth and JWT tokens, so I wasn’t sure if it could be used in this capacity. A quick Google search, and, yes! I sure could.</p><h3>Web Storage</h3><p>As per MDN:</p><blockquote>When writing code for the Web, there are a large number of Web APIs available. Web APIs are typically used with JavaScript, although this doesn’t always have to be the case.</blockquote><p>One of these APIs is the Web Storage API. The Web Storage API —</p><blockquote>provides mechanisms by which browsers can store key/value pairs, in a much more intuitive fashion than using <a href="https://developer.mozilla.org/en-US/docs/Glossary/cookie">cookies</a>.</blockquote><p>Web storage can be implemented in one of two ways: <strong>sessionStorage</strong> or <strong>localStorage.</strong> sessionStorage maintains a storage area that’s available for the duration of the page session. localStorage does the same thing but persists even after the browser is closed and reopened. Since I knew I needed it to persist after the browser is closed, localStorage was my choice.</p><h3>localStorage</h3><h4>Setting Up</h4><p>Invoking and creating localStorage will create an instance of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage">Storage</a> object, through which data items can be set, retrieved and removed. To create a storage object, use the setItem method. It will take two arguments, a set of key/value pairs. Name the first what the key shall be called, and the second your value. In my application, I was using an array to hold my nominations state, so I knew this is what I needed my value to be. localStorage only supports strings as values, so we can use JSON.stringify to convert the array into strings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQYO2UzGFpOQqYI-lR7tuA.png" /><figcaption>Code featuring state and localStorage for nominations</figcaption></figure><p>Now, if I go into my Chrome Dev Tools, this should be accurately represented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KL48MOjbQy934UtUJ1loYw.png" /><figcaption>Chrome Dev Tools</figcaption></figure><p>Nice! There’s a key of nominations that points to a value of an empty array.</p><h4>Adding To</h4><p>Now that my localStorage exists, I need to add nominations to it. In my nominateHandler function(which adds a movie to the nomination state), I’ll add an additional line that also updates localStorage to reflect the updated state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZBg3wfYHB17UAeY661NAJQ.png" /><figcaption>nominateHandler Function</figcaption></figure><p>Now when I add a movie, localStorage will reflect accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_HQ-ITa1VWvOUwIb84MdQ.png" /><figcaption>Chrome Dev Tools with Updated localStorage</figcaption></figure><p>There’s also a removeHandler that removes a nomination and updates state and localStorage using the same logic.</p><h4>Putting It Together</h4><p>While this will update localStorage, should the page be reopened or refreshed, my nominations list on the page won’t be accurately represented since my nominations useState hook is set to an empty array. Using conditional logic, this can be fixed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-eZKuwCoBhYopBZKIK-SA.png" /><figcaption>Updated State Code</figcaption></figure><p>Here, a ternary operator is used to ask the questions <em>“Does the nominations key in localStorage have any values, aka is it not an empty array? If so, set nominations state equal to the values stored in localStorage. If not, set state equal to an empty array”. </em>Notice that to retrieve a value, the getItem method is used. Also notice that since JSON.stringify was used to convert the array to strings, JSON.parse is used to convert back to an array.</p><p>To tie everything together, I implemented the useEffect hook to load my nominations upon reload or reopen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*kLMhbkgY-6ocI7GuhGBBUA.png" /><figcaption>useEffect Hook to Load State</figcaption></figure><h3>Conclusion</h3><p>Using key/value pairs, localStorage stores data during page use and beyond. It has no expiration date, and gets cleared only through JavaScript, or clearing the Browser cache / Locally Stored Data. While not perfect for every situation, it useful for storing lists, carts, etc. in front end apps. Try it for yourself, and see if you can come up with some creative uses for web storage!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=455639017ab3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Block Scope]]></title>
            <link>https://kevinneyer.medium.com/block-scope-f8c451f6e7ca?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8c451f6e7ca</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[block-scope]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[scopes]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 17:41:14 GMT</pubDate>
            <atom:updated>2021-01-08T17:41:14.329Z</atom:updated>
            <content:encoded><![CDATA[<p>Declaring Variables Successfully</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z-ECO-H6UhSB-PpL" /><figcaption>Photo by <a href="https://unsplash.com/@joshuaryanphoto?utm_source=medium&amp;utm_medium=referral">Joshua Reddekopp</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>When working in JavaScript, we, as developers, have to deal with a concept called scope. Simply put, scope is where something lives, and defines where within the context of our code it can be accessed. While there are different types of scope — <a href="https://developer.mozilla.org/en-US/docs/Glossary/Global_scope">global</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions">function</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures#lexical_scoping">lexical</a>, to name a few — I want to talk about block scope.</p><h3>Block Scope</h3><p>When a variable is placed within curly brackets {}, as used in an <strong>if</strong> statement, and <strong>if…else</strong> statements, it falls into consideration for block scope. Where this becomes important is in how we declare variables. There are three ways to declare variables: <strong>var</strong>, <strong>let</strong>, and <strong>const</strong>. <strong>let</strong> and <strong>const </strong>are block scoped, whereas <strong>var</strong> is not. What does this mean? It means that, if you declare <strong>let </strong>or <strong>const</strong> within curly brackets, then it is only accessible inside the curly brackets. Let’s take a look!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*WoObuQlvAM-d3f036BYlzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*ca0AviIgZruZE_LO3TWH1Q.png" /></figure><p>While this may seem quite logical, block scope is something to consider when declaring variables. Plus, it’s a nice little spice to add on to an answer to the common question, “What’s the difference between <strong>var</strong>, <strong>let</strong>, and <strong>const</strong>?</p><h3>Summary</h3><p>In the world of our code, we can put things wherever we want. It is important, however, to see how the arrangement or living spaces of our code(variables, functions, things that may get called upon later) play into the bigger picture. Thinking about scope will help solidify that our code executes and returns the values we set out to achieve. As always, don’t forget to look at the docs and try it for yourself. Happy Coding!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtkYpAbKdWj4TS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtkYpAbKdWj4TS%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FtkYpAbKdWj4TS%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/65603b7d8bf3212287610ef246a3c6d1/href">https://medium.com/media/65603b7d8bf3212287610ef246a3c6d1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8c451f6e7ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep the Change, You Filthy Animal]]></title>
            <link>https://kevinneyer.medium.com/keep-the-change-you-filthy-animal-bf58adda3553?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf58adda3553</guid>
            <category><![CDATA[money]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[home-alone]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Fri, 01 Jan 2021 18:57:35 GMT</pubDate>
            <atom:updated>2021-01-01T18:57:35.023Z</atom:updated>
            <content:encoded><![CDATA[<p>One Way of Using the toFixed Method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q90Lr1VnDAE2BYbC" /><figcaption>Photo by <a href="https://unsplash.com/@joshappel?utm_source=medium&amp;utm_medium=referral">Josh Appel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Getting Started</h3><p>I’ve mentioned in some of my previous articles that I have been working and practicing on a transaction app — a simple application where a user can view and add recent transactions. One practical user story I wanted to implement was being able to see the total of all the transactions. I knew the code to make this happen, so off I went. I put everything in my text editor, saved, and then viewed my app. It was working! Hooray! But, my celebration wasn’t what it should be. This is what I was getting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*0p0f4JjnSI9NPEfPXpnXfQ.png" /><figcaption>Old, Meh Total</figcaption></figure><p>While this is mathematically correct, it’s not formatted in the way we view dollars and cents. Now, how to make it the oh, so glorious, 118.50?</p><h3>The Good Stuff</h3><p>After a brief Google stint, I found my answer: the <strong>toFixed()</strong> method! As stated in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed">MDN</a> docs, the <strong>toFixed()</strong>method formats a number using a fixed point notation. This is perfectly applied when working with money.</p><p>The method takes an optional parameter, which is the number of digits desired after the decimal. But, in this case, since I want change accurately represented(two decimals), the parameter is pretty important!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*mCrnulTGFYw9JfTFiyXGiQ.png" /><figcaption>Examples of Different Parameters.</figcaption></figure><p>Perfect! I updated my code to include the <strong>toFixed()</strong>method, and it looked great.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*ao_mJuAvIRvnRPo1Fszhrw.png" /><figcaption>Updated Code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*yxEtpPwK4vvkkTr8XWYK-Q.png" /><figcaption>New, Glorious Total</figcaption></figure><p>The nice thing about the <strong>toFixed()</strong>method is even if the number contains no decimals, it will put zeros(as many your parameter dictates). Again, perfect for monetary values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*MRd211JjjFkhnArx7kB3CQ.png" /><figcaption>toFixed Example</figcaption></figure><h3>Summing Up</h3><p>The <strong>toFixed()</strong>method is perfect for times when a consistent numerical value is desired — perfect for dealing with monetary values. This way, you can accurately keep the change.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJEwAsGTocxAsM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJEwAsGTocxAsM%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FJEwAsGTocxAsM%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="258" frameborder="0" scrolling="no"><a href="https://medium.com/media/13afccb2d5f7dc0f47505b08d6ceed26/href">https://medium.com/media/13afccb2d5f7dc0f47505b08d6ceed26/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf58adda3553" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It’s a Second Date]]></title>
            <link>https://kevinneyer.medium.com/its-a-second-date-c7d017590c63?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7d017590c63</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[date-object]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 19:27:25 GMT</pubDate>
            <atom:updated>2020-12-23T19:27:25.496Z</atom:updated>
            <content:encoded><![CDATA[<p>Using date objects from your database</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FW2heDDJSLC0thGO7Ld%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FW2heDDJSLC0thGO7Ld%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FW2heDDJSLC0thGO7Ld%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="362" frameborder="0" scrolling="no"><a href="https://medium.com/media/9eb7f85e4861cecae6ab11c41a770c59/href">https://medium.com/media/9eb7f85e4861cecae6ab11c41a770c59/href</a></iframe><h3>Introduction</h3><p>Within the context of my last few blogs, I discussed using the <a href="https://kevinneyer.medium.com/its-a-date-f6dce33678fb">JavaScript date constructor</a> to create and access information from date objects and using <a href="https://kevinneyer.medium.com/json-server-1e9c1bd7a1b7">JSON Server</a> to quickly create databases for prototyping and mocking. This week, I want to combine the two and discuss accessing and using date objects from our database.</p><p>The last couple weeks, I’ve been dusting off and sharpening my React skills. To do this, I decided to re-create my bootcamp React code challenge. But this time, building it from scratch. The objective of the challenge was to modify a transaction ledger so that it fetched transactions from the database and displayed them in a transaction spreadsheet. Users could then add transactions, sort by amount, search by location, and delete transactions. Sounds pretty practical, right?</p><p>To take it up a notch, I wanted to add a few extra features like adding comments, seeing amount totals, and filtering by date and month. It was filtering by date and month that kind of stumped me. Initially, I had transaction dates set in <em>mm/dd/yyyy </em>format. And, when a user added a transaction, they provided the date, as text input, in the same format . My immediate thought was<em>, ‘how would the computer know which date was earlier or later based strictly on text?’ </em>My next thought, <em>store the dates as date objects! </em>Challenge accepted.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FLPrAK9rEedDwjtL1J0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FLPrAK9rEedDwjtL1J0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FLPrAK9rEedDwjtL1J0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="316" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aef7e4438bef86455beff0b73893d9c/href">https://medium.com/media/9aef7e4438bef86455beff0b73893d9c/href</a></iframe><h3>Getting Started</h3><p>I wanted the user to be able to select the date from a calendar, instead of a text input. So, I implemented the npm <a href="https://github.com/wojtekmaj/react-calendar">React-Calendar</a>. This allows dates to be selected from this nice, and useful, calendar, as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*4GqpfjQRoHXd5Z7UdNBuEQ.png" /><figcaption>Calendar Image</figcaption></figure><h3>The Code</h3><p>Within my component, I created state to keep track of the date, and I put an onChange into the calendar so that state would change on each date selected. As per the docs, I set the initial state to be a new date object, representing today’s date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*4QiEbsM3lGKRat1aUwWPBA.png" /><figcaption>Setting Date State</figcaption></figure><p>In my onChange function, I wanted to see what kind of information I was getting. So, I put in a console.log</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*iKL5wfjLlZ7XqV823TtpOg.png" /></figure><p>Much to my liking, I was getting a date object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*3UYT63gi1bW3ZZeHTY3v0Q.png" /><figcaption>Console of dateHandler Function</figcaption></figure><p>Since my end goal was to store this date object in my database and be able to transform it so that when it fetches, I was on the right track. If state is initially set using the date constructor, to update it, use the date constructor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*qkQEJyiDxXiM3xryP9QEAA.png" /><figcaption>Updating the Date State</figcaption></figure><p>Nice! I wanted to try adding a transaction to see what happens. My add function looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*uLcOdtY7q26Dh0LgdNQoCQ.png" /><figcaption>addOne Function</figcaption></figure><p>I checked my db.JSON, and this is what I saw.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*HvbCvILF3u2CvnXs6nlBKQ.png" /><figcaption>db.JSON</figcaption></figure><p>Perfect! Exactly what I needed — a date object. Now, how to transform this to the <em>mm/dd/yyyy </em>format.</p><h3>Making it Look Right</h3><p>In my View Component, which renders the spread sheet, when it receives the state transaction array, the array is mapped over. Each transaction gets its own table row, and each transaction property gets its own cell. From my previous blog, I learned there are many helpful instance methods that come built into date objects. So, I knew I wanted to use the .<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString">toLocaleDateString() </a>method. I initially implemented it like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8F0T5Cvdf4BXZw3mvQDlXw.png" /></figure><p>I was getting an error!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cxlRBWhRuGcKl61-hzdo0A.png" /><figcaption>Error!</figcaption></figure><p>This is due to the fact that, at this point, the component is being given the date as a string, and the instance methods only works on date objects. Easy fix! Throw the <em>transaction.date </em>as an argument into the date constructor to create a new date object with the desired information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGBGj84wRSCqK6d8fylbVA.png" /></figure><p>Perfect! Now my date column is represented in my preferred method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*Tb88sqrl8TnKTAJhrgHRAA.png" /><figcaption>Transaction Table</figcaption></figure><h3>Sort and Filter</h3><p>Step one complete! Now, to sorting and filtering. Having discovered the issue with dates being fetched as strings, I now knew the best way to handle this — put the date information into a date constructor!</p><p>To sort, simply use the sort method, but don’t forget to put your args in the constructor!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqLBeUYcVAL_4vTttaARtg.png" /><figcaption>Sorting by Date</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*mimBrungXK9G3GvOKzRNpA.png" /><figcaption>Dates are Sorted</figcaption></figure><p>To filter by month, use the filter method. Again, don’t forget the args and constructor! The tricky thing about this, though, is in the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth">.getMonth()</a> instance method, January is numerically 0, unlike our conventional 1. So, adjust the months accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-B7zeO6dp8SXbCl1yAnNtQ.png" /><figcaption>January through March Representation</figcaption></figure><h3>Conclusion</h3><p>There are many great and interesting things we can do with dates. The date constructor has many great built in instance methods we can utilize. The important thing to remember: if your date information is coming from your database in JSON, those strings need to be converted into date objects before we can get into the fun stuff!</p><p>I hope my dive into errors, and eventual resolution, has been helpful. As always, dig into this on your own, and have fun. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7d017590c63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON Server]]></title>
            <link>https://kevinneyer.medium.com/json-server-1e9c1bd7a1b7?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e9c1bd7a1b7</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[json-server]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 00:38:49 GMT</pubDate>
            <atom:updated>2020-12-18T00:38:49.944Z</atom:updated>
            <content:encoded><![CDATA[<p>Firing Up a Quick Database</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXsHkc4MCBXDn0yNybG%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FXsHkc4MCBXDn0yNybG%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FXsHkc4MCBXDn0yNybG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/27446109055caee7e60230f14bef205a/href">https://medium.com/media/27446109055caee7e60230f14bef205a/href</a></iframe><h3>Introduction</h3><p>This last week, I’ve been brushing up on ReactJS. When I think React, I think components, state, props, and event handling. As I was jotting down ideas and planning out topics to practice, it occurred to me — I hadn’t touched fetch requests in quite a bit of time. And honestly, the syntax wasn’t popping up rapidly. Not a great realization. However, I could change that! With that in mind, working on fetch requests became my goal. The next thought became — how can I do that without creating a full backend application for my server? I then remembered that some of our bootcamp labs and code challenges had a way for doing this. A little knocking around the old brain cobwebs, and it came to me: JSON Server!</p><h3>What It Is</h3><p>JSON Server is an npm package, and it is a full fake rest API intended for moments when a quick back-end for prototyping and mocking is needed.</p><h3>How to Use</h3><h4>Getting Started</h4><p>Since it is an npm package, to install within the desired project directory, use the command</p><pre>$ npm install json-server</pre><p>This will put JSON Server as a dependency for your project.</p><h4>Setting Up</h4><p>The meat and potatoes of the server will live in a file called db.json. In your file tree, create that file. Then, within that file, since we’re dealing with JSON, create what looks like a plain old JavaScript object. Then within that object, create a key, named whatever you want your endpoint to be named, and have that point to a value of an array. Then, within the array, create objects that will represent the data you’d like to store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*eEQ6EnB2NZSrhpvZMQB9vA.png" /><figcaption>db.json file</figcaption></figure><p>Here, I was working on a banking app, so I created an endpoint called <em>transactions</em>, which points to an array of transactions. Each bit of data can contain as much or as little as you want. My app didn’t need much, so each transaction only has four qualities. The beauty of the JSON server, if I want to add or delete anything, I can go into the file and manually do it. Want to add a category to each transaction, add it! Want to delete one, let it go! No schema, no rollbacks. Plain, simple, and easy.</p><h4>Using It</h4><p>To get your server up and running, use the command.</p><pre>$ json-server --watch db.json</pre><p>The default port this will go to is 3000. To use a different port, simply flag it in your command.</p><pre>$ json-server --watch db.json -p 3001</pre><p>Now, going to ‘<a href="http://localhost:3001/transactions">http://localhost:3001/transactions</a>’ I should see my database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*89_iv-NmUs0m6fh_PwW8NQ.png" /><figcaption>localhost live</figcaption></figure><p>Awesome! The database is up and running! Now, for any fetch requests(get, post, patch, delete), this is my endpoint, and I can run my frontend based off of this.</p><h3>Conclusion</h3><p>JSON Server is a great resource for frontend developers looking to spin up a server quickly and with little effort. It’s perfect for making sure our code is working the way we intend. Give this npm a shot, and hopefully you’ll enjoy using it as much as I do. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e9c1bd7a1b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Queues and Stacks]]></title>
            <link>https://kevinneyer.medium.com/queues-and-stacks-6ea35fb26cae?source=rss-34fd22c9ab6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ea35fb26cae</guid>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[Kevin Neyer]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 20:24:32 GMT</pubDate>
            <atom:updated>2020-12-11T20:24:32.908Z</atom:updated>
            <content:encoded><![CDATA[<p>A quick debriefing on FIFO and LIFO</p><p>Greetings, one and all! With the holiday season upon us, it’s easy to find ourselves feeling festive, joy, and generous. In fact, the holiday season is a perfect time to show love and appreciation with gift giving. And, I couldn’t think of a better gift to myself than continuing study of data structures! This week, I got into the topics of queues and stacks — what they are and how they’re different. If you’re up for some holiday fun yourself, read along!</p><h3>Overview</h3><p>Queues and stacks are linear data structures in which elements can be added or deleted. Nice! This sounds pretty similar to an array, right? For demonstration purposes, I will be using arrays in the examples. Great! Now that we know what they are and how they’re similar, let’s see how they’re different.</p><h3>Queues</h3><p>As stated, queues linearly store data, but they follow a directional pattern or rule for how elements are added or deleted. In a queue, elements are added(enqueued) to the end and removed(dequeued) from the front. In other words, queues operate using the First In, First Out(FIFO) principle. This is a lot like a regular line in which the first person in line is the first person served, and like wise, the last person added to the line is the last person served.</p><p>For example, let’s think of a deli or bakery counter. There’s a little pull tab machine that dispenses numbered tickets in numerical order. There is also a digital screen(or yelling employee) that counts up the numbers so that customers can be helped in the order in which they arrived(FIFO). In code, it could look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*QVsxNwt7t7INkfbKkIxC4Q.png" /></figure><p>To see it in action, let’s add some customer numbers to the line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*NzPScjXcrD2Nf39LgJsZVQ.png" /><figcaption>Adding customers</figcaption></figure><p>Once a customer has been served, we can simply run the beenServed function to remove them from the line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*kA8ScPUcznf5IDdJ-iATsA.png" /><figcaption>Removing customers</figcaption></figure><h3>Stacks</h3><p>Stacks linearly store data, and also follow a directional pattern or rule for how elements are added or deleted. Unlike queues, stacks both add and delete elements from the front. Meaning, the last in is added to the front and is also the first to be deleted. Simply put, stacks operate using the Last In, First Out(LIFO) principle.</p><p>A good example is to picture trays in a cafeteria. After eating, trays are left in a designated tray spot. When a diner is finished eating, they bring their tray to the spot and set it on top of the tray stack. The last used tray(latest element) is added to the top. When going to remove trays, assuming one at a time, we’d have to start with the top and work our way down(LIFO).</p><p>In code, it could look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*LzZu1Lq869q3IyhnsY4OXQ.png" /></figure><p>Assuming each tray has a different color, let’s add some trays and see it in action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Bld4Szof8y5uazbpzOFmvQ.png" /><figcaption>Adding Trays</figcaption></figure><p>When it comes time to clean up, let’s remove trays by running the removeTray function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*oLC_C0DBN9vXScyDsDGPDA.png" /><figcaption>Removing trays</figcaption></figure><h3>Conclusion</h3><p>Queues and stacks are both really useful ways to store, add, and remove data. The main point of concern is how and in what order data is added and removed. Queues — First In, First Out — think of a stereotypical line: first in line is served first, others fall in after the person at the end of the line, and last is served last. Stacks — Last In, First Out— think of a stack of books: new books will be added to the top, and to get the book on the bottom, the top ones need to be removed first.</p><p>As always, research and experiment with these on your own. Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ea35fb26cae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>