samedi 6 février 2021

In what situation would 'a != a' resolve to true in JavaScript?

Looking through the code of svelte.js I found this odd looking function:

function not_equal(a, b) {
    return a != a ? b == b : a !== b;
}

Can someone explain to me in what situation comparing a variable with it self for inequality would resolve to false?

I know that != and == are weaker comparison operators than !== and === because they don't really care about the type but I still can't figure out what makes the not_equal function different from a simple a !== b

Aucun commentaire:

Enregistrer un commentaire