Created
August 3, 2021 04:06
-
-
Save muthhukumar/514907b71cf210c3f8f6f3e7cf6f8a24 to your computer and use it in GitHub Desktop.
custom function that behaves as ===
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 strictEqual(a, b) { | |
if ((Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 0))) { | |
return true | |
} | |
if (Object.is(a, NaN) && Object.is(b, NaN)) { | |
return false | |
} | |
return Object.is(a, b) | |
} | |
console.log(strictEqual(10, 10) === true) | |
console.log(strictEqual(undefined, undefined) === true) | |
console.log(strictEqual(null, null) === true) | |
console.log(strictEqual('10', '10') === true) | |
console.log(strictEqual({}, {}) === false) | |
console.log( | |
strictEqual( | |
function () {}, | |
function () {}, | |
) === false, | |
) | |
console.log(strictEqual(Symbol(), Symbol()) === false) | |
console.log(strictEqual(1n, 1n) === true) | |
console.log(strictEqual(NaN, NaN) === false) | |
console.log(strictEqual(-0, 0) === true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment