Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Remove Unnecessary `Else` Blocks with Guards and Early Returns


    Conditional logic can be very cumbersome and difficult to read. A single if/else block might be simple enough, but nesting several of them can lead to very complicated logic and difficult to read code.

    Often, we can easily eliminate half of the branching through the use of guard statements and early returns. This lesson will take a function with a few nested if/else blocks and refactor it to remove all of the elses. The result will be simpler and, in my opinion, easier to read.