Dee*_*ngh -1 javascript if-statement
面对面试时,我感到很困惑
- if({})console.log("hello")
- if([])console.log("hello")
- if('')console.log("hello")
- if('')console.log("hello")
我知道前三个会打印你好,但我不知道评估的基础是什么.
甚至我想知道几个网站或网址,我可以从中获得这些棘手的问题和解决方案
'',null,undefined和0是falsey的例子,其他都是真的.
if({})
console.log("Empty Object is truthy");
if([])
console.log("Empty array is truthy");
if(' ')
console.log("Space is truthy");
if(!'')
console.log("Empty string is falsey");
if(!null)
console.log("null is falsey");
if(!undefined)
console.log("undefined is falsey");
if(!0)
console.log("Zero is falsey");Run Code Online (Sandbox Code Playgroud)