Have you ever heard of Defensive Programming and the Fail-Fast system design? These are guidelines which tell us to always validate a method's input. Something like this: function sayHi(firstName, lastName) { if (!firstName?.length) throw new E...

Markdown supported · ⌘↵ to post
Phillippe Santana
CTO at INA
The newer and better version of the guard clauses is now available as an NPM package. Go get it at @phillcode/guard, install with
npm i @phillcode/guardor inspect the source code.