Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <body> </body> <script> // 0 和 '' 和 [] 和 false 四者任意比较(==)都为true if(0 == '') { console.log(" . 1 " ) } IF ( 0 == []) { the console.log ( " 2 " ) } IF ( 0 == to false ) { the console.log ( " . 3 " ) } // 0 and '' and [] and {} with the four false compare (==) are false IF ( 0 == {}) { the console.log ( " . 4 " ) } // null and undefined compare (==) is true, and other more are false IF ( null == undefined) { the console.log ( " . 5 " ) } // 0 and 'false, and null and undefined is converted to a Boolean value and default are false IF ( 0 || "" || false || null || undefined ) { the console.log ( " . 6 " ) } // this value for five! operation (the negation operator), the result is full to true the console.log ( ! 0 ) // to true the console.log ( ! '' ) // to true console.log ( !false) //true console.log(!undefined) //true console.log(!null) //true // [] 和 {} 默认为 true if([] && {}){ console.log("7") } </script> </html>
result:
note:
Examples are relatively == instead of ===
On behalf of the same == === strict on behalf of the same, both are different!