logoalt Hacker News

moritzwarhiertoday at 4:16 PM1 replyview on HN

I knew this in and out, but as a Full-Stack PHP/Symfony/Frontend/JS guy who pivoted to mainly TS for b2b stuff, I still have to occasionally enter

  !""

into the browser console just to be sure, during code reviews :D

Replies

tredre3today at 5:21 PM

In JS/TS:

    "0" == false : true
    ""  == false : true
    " " == false : true
    "1" == false : false

    !"0" : false
    !"" : true
    !" " : false
    !"1" : false

In PHP:

    "0" == false : true
    ""  == false : true
    " " == false : true
    "1" == false : false

    !"0" : true
    !"" : true
    !" " : false
    !"1" : false
Honestly the only way to remain sane in either, but especially if you use both, is to always use === and never use boolean logic (!) when a string could be involved.
show 1 reply