Skip to content

Latest commit

 

History

History
23 lines (14 loc) · 576 Bytes

forin.md

File metadata and controls

23 lines (14 loc) · 576 Bytes

Pattern: Unfiltered for ... in

Issue: -

Description

Requires a for ... in statement to be filtered with an if statement.

Rationale:

for (let key in someObject) {
    if (someObject.hasOwnProperty(key)) {
        // code here
    }
}

This prevents accidental iteration over properties inherited from an object’s prototype.

Further Reading