Last active
August 28, 2020 14:35
-
-
Save ir3ne/587cb0b39686869363319084b7935f3e to your computer and use it in GitHub Desktop.
This file contains 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
// Like a === b | |
function strictEquals(a, b) { | |
if (Object.is(a, b)) { | |
// We know a and b are equal so we check only a | |
if (Object.is(a, NaN)) { | |
// Special case #1. | |
return false; | |
} else { | |
return true; | |
} | |
} else { | |
if ( | |
(Object.is(a, 0) && Object.is(b, -0)) || | |
(Object.is(a, -0) && Object.is(b, 0)) | |
) { | |
// Special case #2. | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment