1. [] and! []
[] = =false/ / = >true! [] = =false/ / = >true[] = =! [] / / = >true[] = = [] / / = >false
if( [] )
console.log("true"); / / = >log: "true"
Copy the code
- Can be true or false
[]
2. “and “”
""= =false/ / = >true
""= =false/ / = >true
""= =""/ / = >false
if("")
console.log("true")
else console.log("false") / /log: "false"
if("")
console.log("true") / /log: "true"
Copy the code
- Can be true or false
""
- while
""
Constant for thefalse
3. “0” and 0
0 = =false/ / = >true
"0"= =false/ / = >true
"0"= > / = = 0"true
if("0")
console.log("true") / /log: "true"
Copy the code
- Can be true or false
"0"
0
Constant for thefalse
Mixed 4.
[] = = 0 / / = >true[] = ="0"/ / = >false[] = =""/ / = >false[] = =""/ / = >true0 = =""/ / = >true0 = =""/ / = >true
Copy the code
Conclusion: There are several special cases
-
[] == "" == 0 == false
-
"0" == 0 == false
-
" " == 0 ==false