Skip to content

Commit

Permalink
fix(src): replace ==/!= with ===/!== (#140)
Browse files Browse the repository at this point in the history
Sources such as [D. Crockford][^1] and [MDN][^2] both advise that only
triple equals operator should be used when programming in JavaScript
and double equals operator be ignored altogether.

[^1]:
    https://bytearcher.com/articles/douglas-crockford-javascript-good-parts-book-review/

[^2]:
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
deepsource-autofix[bot] committed Oct 16, 2022
1 parent 7864fa0 commit a013a28
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function objectsEqualShallow(
o1: Record<string, number | RegExp> | null | undefined,
o2: Record<string, number | RegExp> | null | undefined
): boolean {
if (o1 == null || o2 == null) {
if (o1 === null || o2 === null) {
// Null is only equal to null, and undefined to undefined.
return o1 === o2;
}
Expand Down

1 comment on commit a013a28

@DerekNonGeneric
Copy link
Member

@DerekNonGeneric DerekNonGeneric commented on a013a28 Oct 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this was doing a nullish comparison and that the triple equals would mean that undefined would not be accounted for when doing these initial comparisons, which is not what we want because it should be accounted for here.

Please sign in to comment.