• 30_to_50_Feral_PAWGs [she/her]@hexbear.net
    link
    fedilink
    English
    arrow-up
    7
    ·
    1 month ago

    OK, so like…

    • 0 == "0" is true because the script interpreter recognizes that the integer form can be cast to a string value, and then it compares both values as if they were strings.
    • 0 == "\t" is true because a string consisting of only whitespace characters is trimmed down to an empty string, which is considered “falsey.” Numeric zero is also “falsey,” so both values are cast to booleans for comparison purposes.
    • 0 == [] is the same story – an empty array is also falsey, so both the numeric zero and the empty array are cast as booleans when they are compared.
    • None of these comparisons work between the string-form zero character, the tab character (or blank, non-empty string), or the empty array because fuck you, that’s why.

    If you want to get into heresy, here are some excerpts from The Satanic Verses:

    • Boolean(0) == Boolean("") returns true, but Boolean(0) == Boolean("\t") returns false.
    • Boolean(0) == Boolean("0") returns false.
    • Boolean(0) == Boolean([]) returns false.

    The Boolean builtin constructor seems to go off of string length instead of mimicking the == operator’s automatic cast behavior.