Omit needless names
Through separations and recognitions
Separate inputs from environment
Shows a date manipulation example. The function does not take an argument, but uses
new Date()
internally. Then the improved version takes year and month as arguments and returns a calculated value.The above jsbin example shows, that a function that clearly separates its inputs are much easier to test (like the one above). You don't have to mock out secret inputs (like new Date inside)