這幾天用Enki來學習JavaScript,感覺不錯,You can’t handle the truth! 有一些特別True/False例子。這裡簡單記錄一下。
最簡單的測試方法:1234567function test(something){ if (something) { console.log(something + ' is true.'); } else { console.log(something + ' is false.'); }}
例子
Truthy
|
|
以下都是[object Object]:12{a: false}{}
Falsy
|
|
值得注意的是[],它本身會是true
,但如果用[] == true
的話會輸出false
,
而[] == false
的話會輸出true
。