Avoid nested ternary
<p>I wrote code like this:</p>

<pre><code>query = (type) ? (parent) ? { parent: parent } : { type: type } : {}
</code></pre>

<p>I didn't know that nested ternary should be avoided. But what would be a short way to write that correctly?</p>

<p>This seems not to be very short - and I don't know if that is correct:</p>

<pre><code>if (type &amp;&amp; parent)
    query = { parent: parent };
else if (type &amp;&amp; !parent)
    query = { type: type };
else
    query = {};
</code></pre>