Skip to content

Instantly share code, notes, and snippets.

@ir3ne
Last active August 28, 2020 14:35
Show Gist options
  • Save ir3ne/587cb0b39686869363319084b7935f3e to your computer and use it in GitHub Desktop.
Save ir3ne/587cb0b39686869363319084b7935f3e to your computer and use it in GitHub Desktop.
// 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