Clean JavaScript

A concise guide to learning Clean Code, SOLID & Unit Testing

Clean JavaScript

If you are buying from the UK, you can purchase the paper version from here.

Gallery (Spanish version)

About the book

JavaScript is now one of the most popular programming languages in the world. It is used in the critical infrastructures of many very important companies like Facebook, Netflix or Uber.

This is why writing better, higher quality and clearly legible code has become essential. Normally, developers write code without the explicit intention of making it easily understood by other people because we are focused on finding a solution to the problem that works, without thinking about people. Usually, trying to understand the code written by other programmers or even code that we wrote ourselves a few weeks ago, can be quite difficult.

This e-book strives to be a concise reference of how to apply clean code, SOLID, unit testing and TDD, to be able to write more legible, easily maintainable and change tolerant JavaScript code. In this book you will find several references to other authors and simple examples that will help you to find the way to become a better developer.

Table of contents

  • Preface
    • What this book is not.
  • About the author
  • Introduction
  • Technical Debt
    • Kinds of technical debt
    • Refactoring, debts are paid
    • Prevention is better than cure, the rules of simple design
  • Section I: Clean Code
  • What is Clean Code?
  • Variables, names and scope
    • Correct use of var, let y const
    • Pronounceable and expressive names
    • Absence of technical information in the names
    • Establish a ubiquitous language
    • Names by data type
    • Numbers
    • Scope of the variables
  • Functions
    • Function declaration
    • Function Expression
    • Function expression with the arrow function
    • Immediately-invoked Function Expressions (IIFE)
    • Parameters and arguments
    • Indentation size and levels
    • Declarative vs imperative style
    • Anonymous functions
    • Referential transparency
    • DRY Principle
    • Command–Query Separation (CQS)
    • Efficient algorithms
  • Classes
    • Prototype and modern ECMAScript
    • Reduced size
    • Organization
    • Prioritize composition over inheritance
  • Comments and format
    • Avoid using comments
    • Consistent format
  • Section II: SOLID Principles
  • Introduction to SOLID
  • From STUPID to SOLID
    • What is code smell?
    • Singleton pattern
    • Tight Coupling
    • Premature optimization
    • Indescriptive Naming
    • Duplication
  • SOLID principles to the rescue
  • SRP - Single responsibility principle
    • What do we understand by responsibility?
    • Applying the SRP
    • Detecting violations of SRP
  • OCP - Open/Closed principle
    • Applying OCP
    • Adapter pattern
    • Detect violations of OCP
  • LSP - Liskov Substitution Principle
    • Applying LSP
    • Detect violations of LSP
  • ISP - Interface segregation principle
    • Applying the ISP
    • Detect violation of ISP
  • DIP - Dependency Inversion Principle
    • High-level modules and low-level modules
    • Depending on Abstractions
    • Dependency Injection
    • Applying DIP
    • Detecting violations of DIP
  • Section III: Testing & TDD
  • Introduction to testing
  • Types of software tests
    • What do we understand by testing?
    • Manual tests vs automatic tests
    • Functional vs non-functional tests
    • Non-functional tests
    • The Pyramid of testing
    • Ice Cream cone anti-pattern
  • Unit testing
    • Characteristics of the unit tests
    • Anatomy of a unit test
  • Jest, the definitive JavaScript testing framework
    • Features
    • Installation and configuration
    • Our first test
    • Asserts
    • Organisation and structure
    • State management: before and after
    • Code coverage
  • TDD - Test Driven Development
    • The three laws of TDD
    • Red-Green-Refactor cycle
    • TDD as a design tool
    • Implementation strategies, from red to green
    • TDD Limitations
  • Practical TDD: The FizzBuzz Kata
    • The code katas
    • The Fizzbuzz kata
    • Exercise statement
    • Designing the first test
    • We run and… red!
    • We go green
    • Adding new tests
    • Refactoring the solution, applying pattern matching.
  • References

DRM free format

The book is generated in three completely DRM-free formats: MOBI, in case you use a Kindle to read your e-books, epub and pdf.


Free updates

Although the book is complete, it is frequently updated to continue refining it. We will send you all updates free of charge. Last updated in May 2021.


Transparency

Most of the profits will be dedicated to growing and giving visibility to the community. We also reserve a part to promote local events related to software development.


Satisfaction guarantee

Remember that if it is not what you expect, we will refund your money. During the first 15 days of purchase, you can get a 100% refund. Zero risk, high potential benefit.


Clean Code is written in a way that makes it easy for someone else to understand, (or yourself in the future)

By Miguel A. Gómez (Author)

Happy reading!

.