JavaScript ?? ??
JavaScript Boolean Object
Boolean ??? Boolean ????? ??, ? ??? ??? ? ?? ??? ?(true)? ??(false)? ????? ????. ?? ??? ???? ??? ??? ????.
//Constructor
new Boolean(value);
//Conversion function
Boolean(value);
value ????? ??? ?? ? ????. ?? ????? ?? ??? ??? ?? ? ????. ? ? ??? ???? ?? ??? ?? ??? ? ????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> document.write( typeof(new Boolean(1)) + '<br />' ); document.write( typeof(Boolean(1)) ); </script> </head> <body> </body> </html>
? ??? ???? ??? ??? ????.
object
boolean
???? ???? ?? ? ? ????. (? ?? ??)? ?? ?? ???? ??? ?????. ?? ??? ???? ?? ?? ????.
??: Boolean ??? Boolean ?? ?? ????? ??? ? ?? ??? ??? ?????.
Tips
? ????? 0, -0, null, "", false, unundefined ?? NaN?? ????? ????? ??? ?? Boolean ??? false? ????, ??? ??? true???. .
Boolean ??? false? ???? ??? if ???? ??? true???.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> var obj1 = new Boolean(false); if( obj1 ){ document.write( '1' ); }else{ document.write( '2' ); } </script> </head> <body> </body> </html>
? ??? ???? 1? ?????. ? ??? obj1? false? ??? ????? ???? if ?? ? obj1? ?? ?? ?? ????? ??? ?? ??? ???? true? ???? ??? ???? ????. ?? obj1 ??? ??? ?? ??? ?? ??? ????.