Search

Primitive Obsession

I found this essay Primitive Obsession by Andrew Cairns interesting. The big example in it is this:

$user = new User('abc123', 'email@address.com');Code language: JavaScript (javascript)

Here the User function takes two string params, string being a primitive type, and here, quite easy to screw up by passing them in the wrong order and/or not pre-validating the values. If you agree, there are a variety of ways to tackle this problem which generally boil down to passing in a typed object. TypeScript and Zod fans will be like: yeah duh.

It's time to take your JavaScript to the next level

Frontend Masters logo

Frontend Masters is the best place on the web to really learn JavaScript. We have a complete learning path from the biggest and best teachers in JavaScript to help you make the most out of the web's biggest language.

One response to “Primitive Obsession”

  1. Avatar Andrew says:

    Glad you found the article interesting! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *