Pattern: Implicit length or size check
Issue: -
Use explicit comparisons when checking array length or collection size for better code clarity. Avoid implicit checks like !array.length
or indirect comparisons like array.length < 1
.
Example of incorrect code:
const isEmpty = foo.length == 0;
const isEmpty = foo.length < 1;
const isEmpty = !foo.length;
const isEmpty = !(foo.length > 0);
const isEmptySet = !foo.size;
Example of correct code:
const isEmpty = foo.length === 0;