Falsey values in JavaScript

后端 未结 6 1334
情歌与酒
情歌与酒 2020-11-27 06:13

I had an interesting interview question today that stumped me a little. I was asked about falsey values. So undefined, NaN, null, 0, and an empty string all evaluate to fals

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:57

    It is important to know that 0 evaluates to false to prevent doing things like:

    if(str.indexOf('foo'))
    

提交回复
热议问题