Skip to content

Instantly share code, notes, and snippets.

@d4vsanchez
Created August 1, 2021 14:53
Show Gist options
  • Save d4vsanchez/209266d810aab81210c5e5107c269ddd to your computer and use it in GitHub Desktop.
Save d4vsanchez/209266d810aab81210c5e5107c269ddd to your computer and use it in GitHub Desktop.
strictEquals implementation without using === or !== operator
function strictEquals(a, b) {
// If one is NaN, we'll always receive false anyway
if (Object.is(a, NaN)) {
return false;
}
// -0 and 0 special case
if ((Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 0))) {
return true;
}
return Object.is(a, b);
}
module.exports = strictEquals;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment