Tyler Hawkins
Mar 5, 2021

--

Thanks Christian! What you've said is true to an extent, but I don't think it's a problem with the `&&` operator per se.

Kent points this out in his article too that his downfall was using `contacts.length` in his code rather than `contacts.length > 0` or `!!contacts.length` or `Boolean(contacts.length)`, not necessarily the usage of the `&&` operator.

So it really comes down to personal preference and the tradeoff of whether you like having the extra `: null` in your code or if you can remember to be careful in how you evaluate the length of an array in your conditional.

--

--

Tyler Hawkins
Tyler Hawkins

Written by Tyler Hawkins

Staff software engineer. Continuous learner. Educator. http://tylerhawkins.info

No responses yet