Write looseEquals(a, b) that returns the same result as a == b, without using == or !=.
looseEquals(a, b) returns what a == b returns, for any two values, without using == or !=.
Follow IsLooselyEqual, the steps the ECMAScript specification gives for ==. Cover each of its rules: no conversion when the types match, the null and undefined rule, booleans to numbers, objects to primitives, strings compared with numbers or BigInts, and numbers compared with BigInts.
You can use ===, typeof, Number, and BigInt. You don't need to handle document.all.
function looseEquals(a, b) {
// your code
}
// looseEquals(null, undefined); // true
// looseEquals(null, 0); // false
// looseEquals("1", 1); // true
// looseEquals([], false); // true
// looseEquals(NaN, NaN); // false
// looseEquals(1n, "1"); // true
// looseEquals(2n, 2); // true
The answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…