Skip to content

Files

Latest commit

 

History

History
23 lines (17 loc) · 557 Bytes

explicit-length-check.md

File metadata and controls

23 lines (17 loc) · 557 Bytes

Pattern: Implicit length or size check

Issue: -

Description

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.

Examples

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;