When a standard language feature already does the job, use it instead of a manual or custom reimplementation — this is clearer, less error-prone, and easier to maintain. Examples observed in review:
Array.isArray(x) instead of a hand-rolled isArray() helper.str.endsWith('...') instead of str.slice(-3) === '...' plus a redundant length check.str.startsWith('--no-') instead of flags.indexOf('--no-') !== -1, since indexOf can match the substring anywhere, not just at the start.undefined:
// instead of
allowExcessArguments(allowExcess) {
if (allowExcess === undefined) allowExcess = true;
...
}
// prefer
allowExcessArguments(allowExcess = true) {
...
}
Object.prototype.hasOwnProperty.call(obj, key) instead of the in operator when you only want to check the object’s own properties (the in operator also matches inherited properties).[eE]) over a blanket /i flag, so the intent of what varies is explicit rather than silently affecting the whole pattern.Before writing custom logic, check whether a native method or language feature already covers the case; it communicates intent more clearly to readers and avoids subtle bugs from incomplete reimplementations.