Skip to content
JavaScript·Advanced·Conceptual·1 min read

What does the ! operator's implicit boolean coercion cause in !someArray.length?

Short interview answer

It coerces the length number to a boolean using truthiness rules first, so this correctly checks for an empty array since 0 is falsy and any positive length is truthy — the double negation !! pattern is often used to make this explicit boolean conversion visible.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Equality and type coercion

Related questions