Using the switch(true) pattern in JavaScript
I prefer early return pattern.<p>Which would look like this:<p><pre><code>    const user = {
        firstName: &quot;Seán&quot;,
        lastName: &quot;Barry&quot;,
        email: &quot;my.address@email.com&quot;,
        number: &quot;00447123456789&quot;,
    };

    if (!user) {
        throw new Error(&quot;User must be defined.&quot;);
    }

    if (!user.firstName) {
        throw new Error(&quot;User&#x27;s first name must be defined&quot;);
    }

    if (typeof user.firstName !== &quot;string&quot;) {
        throw new Error(&quot;User&#x27;s first name must be a string&quot;);
    }

    return user;</code></pre>