Created
August 1, 2021 14:53
-
-
Save d4vsanchez/209266d810aab81210c5e5107c269ddd to your computer and use it in GitHub Desktop.
strictEquals implementation without using === or !== operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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