Pattern: Object literal comparison
Issue: -
Comparing a variable directly with an object or array literal will always return false because each literal creates a new reference. Use appropriate methods to check object or array properties instead.
Example of incorrect code:
if (obj === {}) {
// Always false
}
if (array !== []) {
// Always true
}
Example of correct code:
if (Object.keys(obj).length === 0) {
// Properly checks if object is empty
}
if (array.length === 0) {
// Properly checks if array is empty
}