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

One response to “Primitive Obsession”

  1. Andrew says:

    Glad you found the article interesting! 🙂

Leave a Reply

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

Did you know?

Frontend Masters Donates to open source projects. $363,806 contributed to date.