<?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 Mike Clancy on Medium]]></title>
        <description><![CDATA[Stories by Mike Clancy on Medium]]></description>
        <link>https://medium.com/@mike.clancy.power?source=rss-0671ba79316c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*O8GFUvlX04dbwIh6</url>
            <title>Stories by Mike Clancy on Medium</title>
            <link>https://medium.com/@mike.clancy.power?source=rss-0671ba79316c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:08:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mike.clancy.power/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[.zshrcwxyz]]></title>
            <link>https://medium.com/tech-at-power/zshrcaweoiuchx-23459d5c3012?source=rss-0671ba79316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/23459d5c3012</guid>
            <dc:creator><![CDATA[Mike Clancy]]></dc:creator>
            <pubDate>Fri, 24 Oct 2025 18:39:32 GMT</pubDate>
            <atom:updated>2025-10-24T20:26:37.292Z</atom:updated>
            <content:encoded><![CDATA[<p>Exploring the Potentials of the.zshrc File</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uvnaQQ-hZOmccdrM1aSoMg.png" /><figcaption>Alphabet soup spelling out .zshrc</figcaption></figure><p>If you’ve never seen or worked with the .zshrc file before, you may think it just looks like another one of those alphabet soup files that you find laying around deep into your file system. Like a warm bowl of alphabet soup, .zshrc transforms your terminal from a bare, frigid workspace to a productivity hot spot.</p><h3>What is .zshrc in the First Place?</h3><p>First off, we’ll address the pronunciation. In most cases, it’s pronounced “<em>z shell r c</em>”. In some cases, you may call it by its government name, “<em>z s h r c</em>”, for the sake of clarity.</p><p>With that out of way, what is it? .zshrc runs whenever you start a new Zsh (Z shell) shell. The “zsh” tells you that it’s for the Zsh shell (the default shell for the macOS terminal), and the “rc” indicates that it contains run commands.</p><p>In short, .zshrc is where you write commands that you can use to customize your Zsh shell as well as automate certain processes that you want to be run for each Zsh shell.</p><p>Let’s now take a look at some fun things that we can do with .zshrc.</p><h3>Environment Setup: Taming the $PATH with the path Array</h3><p>For developers, the <strong>$PATH</strong> environment variable, which tells your shell where to look for executable programs, can quickly become a mess. New tools, language managers, and packages all want to add their directories, often leading to a long, hard-to-read, and inefficient variable string.</p><p>Zsh offers a superior, more robust solution: the <strong>path array</strong>.</p><p>Instead of directly manipulating the colon-separated $PATH string, Zsh lets you treat it as a standard array. This allows you to append, prepend, and deduplicate paths with clean array operations, ensuring speed and sanity.</p><h4>With the Path Array</h4><p>Here’s how you can switch from the traditional method to using the path array in your .zshrc:</p><pre># 1. Ensure the paths you want are in the &#39;path&#39; array<br># Prepend a new directory to be searched first (e.g., for Homebrew):<br>path=(/opt/homebrew/bin $path)<br><br># Append a new directory to be searched last (e.g., a custom script directory):<br>path+=(~/scripts)<br><br># 2. Automatically remove duplicates and empty entries<br>path=($path:u)<br><br># 3. Zsh automatically exports this array to the<br># standard $PATH environment variable for all programs<br># to use. No need to call &#39;export PATH=...&#39;</pre><h4>One Step Further: Conditional Environment Variables</h4><p>If you’re a more experienced user of .zshrc, you likely have more advanced workflows. A more powerful use of environment setup involves checking what machine you are on and setting variables accordingly. This is crucial for developers who switch between personal laptops and work environments.</p><pre># Environment Setup: Set different AWS profiles based on the hostname<br>if [[ $HOST == &quot;my-work-laptop&quot; ]]; then<br>  export AWS_PROFILE=&quot;power_remodeling_prod&quot;<br>  export EDITOR=&quot;code&quot;  # VS Code for work<br>else<br>  export AWS_PROFILE=&quot;personal_sandbox&quot;<br>  export EDITOR=&quot;vim&quot;   # Vim for personal projects<br>fi</pre><p>This snippet checks the machine’s hostname and automatically configures a critical environment variable (AWS_PROFILE) and a tool preference (EDITOR), eliminating a major source of configuration error and context switching. This could also be helpful if you’re working within multiple Power repos at once and need to have different environment variables for each repo.</p><h3>2. Shell Customization &amp; Aliases: Making ls Indispensable</h3><p>Shell customization goes beyond just setting environment variables. It involves adjusting built-in command behavior to give you better immediate feedback. The classic example is the ls (list directory contents) command.</p><h4>Persistent ls Behavior</h4><p>We can customize ls by combining a new environment variable setting and a simple alias.</p><p>First, set the LS_OPTIONS variable to include flags you always want:</p><pre># Environment Setup: Set global options for the &#39;ls&#39; command<br>export LS_OPTIONS=&#39;--color=auto&#39;</pre><p>Next, create an alias to make the command more useful by default. Here we use the common l alias, which lists files in a long format (-l), shows hidden files (-a), and prints file sizes in human-readable format (-h):</p><pre># Alias: Create a powerful shortcut for listing files<br>alias l=&quot;ls -lahF --group-directories-first&quot;</pre><p>Now, typing l gives you a clean, color-coded, detailed list with directories appearing first, which is a significant quality of life improvement and saves time looking up file permissions and sizes.</p><h3>3. Functions: Building Context-Aware Workflow Automation</h3><p>While aliases are static replacements, functions allow you to write conditional logic and handle arguments, making them essential for complex, multi-step tasks.</p><h4>The up Function</h4><p>When working on a project, you may frequently navigate into nested component directories. Within .zshrc, we can define a function named root that intelligently detects where you are and bumps you out to the project root. In this case, you’ll , saving several cd ../ steps.</p><p>We will create a function named root that simplifies moving to the repository root:</p><pre># Function to navigate directly to the root of the current Git repository.<br>function root() {<br>  # Use &#39;git rev-parse --show-toplevel&#39; to find the absolute path of the repository root.<br>  # We suppress stderr (2&gt;/dev/null) to avoid printing git errors if not in a repo.<br>  local repo_root=$(git rev-parse --show-toplevel 2&gt;/dev/null)<br>  <br>  if [[ -n $repo_root ]]; then<br>    echo &quot;Navigating to Git repository root: $repo_root&quot;<br>    cd &quot;$repo_root&quot;<br>  else<br>    echo &quot;Error: Cannot find Git repository root. You must be inside a Git repository.&quot;<br>  fi<br>}</pre><p>Now, a developer inside any component subdirectory can simply type root to quickly get back to the project root, which significantly cuts down on directory navigation time.</p><h4>The Recursive mcd Function</h4><p>A highly useful, powerful function for developers is one that can <strong>m</strong>ake a <strong>c</strong>lean <strong>d</strong>irectory and move into it immediately. While simple, it saves two steps hundreds of times over the life of a project. We can make it even better by adding input validation.</p><pre># Function: Make directory and CD into it immediately<br>function mcd() {<br>  # Validate that an argument was provided<br>  if [ -z &quot;$1&quot; ]; then<br>    echo &quot;Usage: mcd &lt;directory_name&gt;&quot;<br>    return 1<br>  fi<br>  # Use the standard mkdir command with the provided argument<br>  mkdir -p &quot;$1&quot; &amp;&amp; cd &quot;$1&quot;<br>}</pre><p>This function utilizes the &amp;&amp; operator to ensure that the cd &quot;$1&quot; command only executes if the mkdir -p &quot;$1&quot; command is successful. The -p flag creates parent directories if they don&#39;t exist, making this function robust and extremely efficient for setting up new feature branches or project folders.</p><h3>Give It a Try Yourself!</h3><p>Hopefully, this has inspired you to check in with your .zshrc. When’s the last you did that anyway? If it’s been a while, take a gander at your .zshrc and try out one of these enhancements. It’s just one nano .zshrc away.</p><p><em>This post is written by a Power Code Academy Student Developer.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23459d5c3012" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-at-power/zshrcaweoiuchx-23459d5c3012">.zshrcwxyz</a> was originally published in <a href="https://medium.com/tech-at-power">Tech at Power</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Objects in Rails]]></title>
            <link>https://medium.com/tech-at-power/service-objects-in-rails-d2afe57c4d88?source=rss-0671ba79316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2afe57c4d88</guid>
            <category><![CDATA[service-object]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Mike Clancy]]></dc:creator>
            <pubDate>Fri, 19 Sep 2025 15:22:33 GMT</pubDate>
            <atom:updated>2025-09-25T13:48:24.716Z</atom:updated>
            <content:encoded><![CDATA[<h3>Running Your Code Like a Kitchen</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNfxSECIoUpO3q98DNC3dg.png" /><figcaption>Cooks in a Kitchen. Too many? Perhaps.</figcaption></figure><p>Let’s think for a moment about a restaurant’s kitchen. There are stations dispersed throughout the kitchen setup for a specific task with a chef that is specialized to doing just that task. A single chef isn’t running around trying to do everything at once with every utensil and tool piled around him. That would look less like a kitchen and more like Neil Peart’s drum kit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/0*birSm6zwHWxkzE-h" /><figcaption>Neil Peart surrounded by drums. Unrelated to my kitchen metaphor; just wanted to sneak this in.</figcaption></figure><p>That’s where service objects come in. They’re like the specialized chefs in a well-run kitchen: each one is responsible for a single task, executed flawlessly, so the whole operation runs smoothly.</p><h3>Service Objects Outside the Kitchen</h3><p>In Rails applications, it’s easy for controllers or models to become overloaded with responsibilities. A single controller action might validate input, create multiple records, apply business rules, and trigger background jobs or emails. Over time, this can make the code difficult to read, maintain, and test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zgmX8XDnrW_sEIgONWrQSg.png" /><figcaption>ChatGPT’s Idea of a Service Object</figcaption></figure><p>A common solution is to introduce a <strong>Service Object</strong>: a “plain old” Ruby object (PORO) dedicated to handling one specific piece of business logic.</p><h4>PORO? What Does It Have to do With Being Old?</h4><p>A PORO is just a regular Ruby class; it doesn’t inherit from Rails components like ApplicationRecordor ApplicationController. That makes it lightweight and flexible. It’s just a “plain old” class that lets you create “plain old” Ruby objects.</p><p>By extracting logic into a Service Object, we achieve cleaner controllers, reusable code, and simpler testing.</p><h3>The Kitchen Nightmare: Fat Controller</h3><p>Here’s a controller that has taken on too many tasks:</p><pre>class DishesController &lt; ApplicationController<br>  def create<br>    @dish = Dish.new(dish_params)<br><br>    if @dish.save<br>      # Too much logic here!<br>      raise &quot;We’re out of beef Wellington!&quot; unless @dish.ingredients.available?<br><br>      GrillStation.cook(@dish)<br>      PlatingStation.plate(@dish)<br>      GordonRamseyMailer.yell(@dish).deliver_later<br><br>      redirect_to @dish, notice: &quot;Dish is ready — service!&quot;<br>    else<br>      render :new, alert: &quot;It’s raw!&quot;<br>    end<br>  end<br>end</pre><p>This controller is trying to:</p><ul><li>Save the dish to the backend</li><li>Check ingredients to determine if there are enough for the dish</li><li>Cook the dish</li><li>Plate the dish</li><li>Send an email to Gordon Ramsay</li><li>Redirect to the dish show page.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxvErBQjc0RjDftUWmIJow.png" /><figcaption>Chef Doing all of the Tasks</figcaption></figure><p>That’s way too much responsibility for one controller action. It’s getting too caught up in the logic involved in creating a dish when it should be focused on connecting the model to the view.</p><h3>Let’s Give that Logic to DishPreparer</h3><p>Instead, we’ll delegate the work to a <strong>service object</strong>:</p><pre># app/services/dish_preparer.rb<br>class DishPreparer<br>  def initialize(dish)<br>    @dish = dish<br>  end<br><br>  def call<br>    ActiveRecord::Base.transaction do<br>      @dish.save!<br>      check_ingredients<br>      cook_dish<br>      plate_dish<br>      @dish.update!(status: &quot;served&quot;)<br>    end<br>    @dish<br>  rescue =&gt; e<br>    GordonRamsey.yell(e.message)<br>    @dish.update!(status: &quot;ruined&quot;)<br>    nil<br>  end<br><br>  private<br><br>  def check_ingredients<br>    raise &quot;We’re out of beef Wellington!&quot; unless @dish.ingredients.available?<br>  end<br><br>  def cook_dish<br>    GrillStation.cook(@dish)<br>  end<br><br>  def plate_dish<br>    PlatingStation.plate(@dish)<br>  end<br>end</pre><p>Now, all of that logic lives inside our DishPreparer service object, not the controller. This extrapolates the logic into a reusable PORO.</p><h3>The Lean Controller</h3><p>Our controller action is lean and easy to read:</p><pre>class DishesController &lt; ApplicationController<br>  def create<br>    dish = Dish.new(dish_params)<br><br>    if DishPreparer.new(dish).call<br>      redirect_to dish, notice: &quot;Dish is ready — service!&quot;<br>    else<br>      render :new, alert: &quot;It’s raw!&quot;<br>    end<br>  end<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyKbusSaz44gRe15IbBzZQ.png" /><figcaption>Lots of chefs in the kitchen</figcaption></figure><p>Instead of being the overworked line cook, the controller is now freed up to do what a head chef should do: delegate dishes to other chefs to cook while ensuring the kitchen runs smoothly.</p><h3>Why This Works</h3><p>Using service objects gives you all the benefits of a well-run kitchen:</p><ul><li><strong>Clarity</strong> → Each object has one responsibility.</li><li><strong>Reusability</strong> → The DishPreparer can be reused anywhere in the app.</li><li><strong>Testability</strong> → You can test the “chef” (service object) independently.</li><li><strong>Maintainability</strong> → Adding a new dish (or step) means updating one dedicated object, not a bloated controller.</li></ul><h3>Conclusion</h3><p>Rails apps, like professional kitchens, run best when everyone knows their role. Keep your controllers clean, your models lean, and let service objects handle the cooking.</p><p>If your controller logic is looking like a Trader Joe’s checkout line, it’s time to tell that extra logic to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*eVA1WTJDtVXuBojusUxyvg.gif" /><figcaption>Get out</figcaption></figure><p>…and go into a service object.</p><p><em>This post is written by a Power Code Academy Student Developer.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2afe57c4d88" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-at-power/service-objects-in-rails-d2afe57c4d88">Service Objects in Rails</a> was originally published in <a href="https://medium.com/tech-at-power">Tech at Power</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Falsy Seven: JavaScript’s Deadly Sins]]></title>
            <link>https://medium.com/tech-at-power/the-falsy-seven-javascripts-deadly-sins-114ff740ee53?source=rss-0671ba79316c------2</link>
            <guid isPermaLink="false">https://medium.com/p/114ff740ee53</guid>
            <dc:creator><![CDATA[Mike Clancy]]></dc:creator>
            <pubDate>Mon, 07 Jul 2025 19:23:18 GMT</pubDate>
            <atom:updated>2025-07-21T17:59:38.500Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>False in name. Fatal in effect.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zEVyLo3o4dYmmMEN" /><figcaption>Photo by <a href="https://unsplash.com/@clevelandart?utm_source=medium&amp;utm_medium=referral">The Cleveland Museum of Art</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Javascript, like most other programming languages, uses Boolean values: <em>true</em> and <em>false</em>. Unlike many other languages, Javascript is unusually aggressive in how it converts values into Boolean values. All values are evaluated in Boolean contexts despite them not being a Boolean type.</p><p>In contrast to Ruby where only <em>false</em> and <em>nil</em> are falsy, Javascript has five additional values of various types that evaluate to false. Javascript’s coercion of values of different data types to true or false means there are some unexpected or counterintuitive cases such as where one value of a data type is coerced into a different Boolean value than another value of the same data type (the number 0 vs 3, for instance).</p><h3>What is “<em>Falsy”</em>?</h3><p>A value is considered <strong>falsy</strong> if it evaluates to false when used in a Boolean context. For example, this could be inside an if statement or when passed to the Boolean() function.</p><p>I hear you saying, “But that’s not very specific. I don’t want to have to run every value through Boolean() to know if it’s truthy or falsy.” Worry not because there are only 7 values that will ever be returned as false in Javascript.</p><p>Not knowing these values can cause confusion and bugs if not considered carefully as not all of them seem logical on the surface. Allow me to introduce you to <em>The Falsy Seven: JavaScript’s Deadly Sins</em></p><h3>The Seven Falsy Values in Javascript</h3><p>Let us now meet the seven values in Javascript that will deceive and confuse you and your code</p><h4>1. false — The Liar</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5JT6qWL5A3D0W_M2" /><figcaption>Photo by <a href="https://unsplash.com/@hartonocreativestudio?utm_source=medium&amp;utm_medium=referral">Hartono Creative Studio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Pride</strong></p><p><strong>Crime:</strong> Claims to be the only source of falseness, but the others learned from it.</p><p>This is the one we know. It is the root of all falsehood in Javascript. It is what every falsy value aspires to be and what they return when evaluated in a Boolean context.</p><pre>if (false) {<br> console.log(“Won’t run”);<br>}</pre><h4>2. 0 — The Slacker</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U3OEise9wC59ixbv" /><figcaption>Photo by <a href="https://unsplash.com/@kennyzhang29?utm_source=medium&amp;utm_medium=referral">- Kenny</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Sloth</strong></p><p><strong>Crime:</strong> Refuses to be truthy like the rest of its number siblings</p><p>Zero, in all of its forms, is falsy. This includes:</p><ul><li>0</li><li>-0</li><li>0n (BigInt zero)</li><li>Binary 0b0, octal 0o0, and hex 0x0</li></ul><pre>const score = 0;<br>if (score) {<br>  console.log(&quot;You scored!&quot;); // Won&#39;t run<br>}</pre><h4>3. “” (empty string) — The Hollow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XIoM72cBcdmPm1HZ" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Envy</strong></p><p><strong>Crime:</strong> Wishes it were a real string with something to say.</p><p>Empty strings <em>are</em> strings, but they are <em>still</em> false. They are jealous of their non-empty brethren and wish to have characters like them.</p><pre>const name = &quot;&quot;;<br>if (name) {<br>  console.log(&quot;Hello, &quot; + name); // No log will be created<br>}</pre><h4>4. null — The Ghost</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kcL0u0Qq35IT-1c2" /><figcaption>Photo by <a href="https://unsplash.com/@jsycra?utm_source=medium&amp;utm_medium=referral">Siyuan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin: Desire</strong></p><p><strong>Crime:</strong> Wants nothing more than to have value but is in a state of having neither value nor existence</p><p>null is Javascript’s embodiment of the absence of value.</p><pre>const data = null;<br>if (data) {<br> console.log(“Data exists”); // It doesn&#39;t<br>}</pre><h4>5. undefined — The Forgotten</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PGh6ytqSy4VSew1B" /><figcaption>Photo by <a href="https://unsplash.com/@kelli_mcclintock?utm_source=medium&amp;utm_medium=referral">Kelli McClintock</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Gluttony</strong></p><p><strong>Crime:</strong> Gobbles up your memory with no value</p><p>undefined is the default value of variables. Until you assign value to a variable, it is undefined.</p><pre>let result;<br>if (result) {<br> console.log(“Here&#39;s the result”); // There won&#39;t be a result<br>}</pre><h4>6. NaN — The Wrath</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bSUiXGVXBO0uf5ZK" /><figcaption>Photo by <a href="https://unsplash.com/@randylaybourne?utm_source=medium&amp;utm_medium=referral">Randy Laybourne</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Wrath</strong></p><p><strong>Crime:</strong> You tried math. It fought back.</p><p>NaN is returned from operations that evaluate to undefined or numbers that aren’t able to be represented.</p><pre>const value = Math.sqrt(-1);<br>if (value) {<br> console.log(“This is a number”); // It&#39;s not<br>}</pre><h4>7. document.all — The Relic</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hXe0eoFQhSz0Zn1Y" /><figcaption>Photo by <a href="https://unsplash.com/@jeremythomasphoto?utm_source=medium&amp;utm_medium=referral">Jeremy Thomas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Sin:</strong> <strong>Greed</strong></p><p><strong>Crime:</strong> Wants to be <em>everything</em>. It exists but is treated like it doesn’t.</p><p>This is a deprecated method that returns all of the elements in a document. While it has everything in it, it is still undefined and falsy.</p><pre>if (document.all) {<br> console.log(“This is truthy”); // It&#39;s actually falsy<br>}</pre><h4>The False Falsies</h4><p>What about [] and {}? While an empty <em>string</em> is falsy, an empty <em>array</em> or <em>object</em> is actually truthy! This is an important distinction and likely the biggest contributor to confusion.</p><p>If you’d like [] or {} to be falsy, you’ll have to look at their length compared to zero.</p><pre>const list = []<br>if(list.length !== 0){<br>   console.log(&quot;I&#39;m truthy&quot;); // This would not run since it&#39;s falsy<br>}</pre><pre>const object = {}<br>if(Object.keys(object).length !== 0){<br>   console.log(&quot;I&#39;m truthy&quot;); // This would not run since it&#39;s falsy<br>}</pre><h3>Why Does Any of this Matter?</h3><p>Falsy values can break your logic without throwing errors. They simply evaluate to false and cause your conditions to be skipped. An example could be when a user inputs 0, and you’re testing if it’s a value number.</p><pre>const userInput = 0;<br>if (userInput) {<br> console.log(“Valid input”); // 0 is valid for this use case but the logic doesn&#39;t think so<br>}</pre><p>Not addressing the above can be a real problem if you consider 0 to be a valid input.</p><h3>Conclusion</h3><ol><li>false</li><li>0</li><li>“” (empty string)</li><li>null</li><li>undefined</li><li>NaN</li><li>document.all</li></ol><p>These seven are silent killers. You’ll receive no warning about their falsehood, so be ye warned and take heed to write safer code. They will betray your expectations if you are not paying attention.</p><p>Know your enemy, and your code will survive the onslaught of the seven falsy values.</p><p><em>This post is written by a Power Code Academy Student Developer.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=114ff740ee53" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-at-power/the-falsy-seven-javascripts-deadly-sins-114ff740ee53">The Falsy Seven: JavaScript’s Deadly Sins</a> was originally published in <a href="https://medium.com/tech-at-power">Tech at Power</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>