Why is 'false' truthy in javascript?

前端 未结 5 1797
面向向阳花
面向向阳花 2021-01-19 10:46

I understand that an empty string is falsy in javascript and a not-empty string is truthy in javascript.

However, why is \'false\' truthy in javascript,

5条回答
  •  甜味超标
    2021-01-19 11:23

    It's by definition. It's a string and it is handled as such. No matter the meaning of the string.

    If your logic would be applied. Then how about following examples:

    "1+3==2"
    "humans have four eyes"
    

    Are they also falsy?

提交回复
热议问题