真值和假值:在 javascript 中,真值和假值用于确定布尔值中的值是 true 还是 falsecontext.这个概念对于使用 if 语句等条件控制程序流程至关重要。falsy values: 0," ",null,nan,false,undefined 登录后复制console.log(boolean(0)); //false登录后复制console.log(boolean(undefined)); //false登录后复制console.log(boolean(' ')); //empty false登录后复制console.log(boolean(null)); //false登录后复制console.log(boolean(nan)); //false not a number登录后复制console.log(boolean(false)); //false登录后复制真值:任何非假值:console.log(boolean(1)); //true登录后复制登录后复制console.log(boolean(1833933)); //true登录后复制console.log(boolean(-1)); //true登录后复制console.log(boolean("hello")); //true登录后复制console.log(boolean(1)); //true登录后复制登录后复制console.log(boolean([])); //true empty array登录后复制console.log(boolean({})); //true empty object登录后复制console.log(function (){}); //true登录后复制example:登录后复制 t flet cash =255 //0 ; //conditions false statement block not runif (cash){ console.log("you can buy burger with drink"); }else{ console.log("you can buy burger"); }else{ console.log("you don't have money"); }登录后复制let a;console.log(a); //false登录后复制output:undefined 登录后复制let a = 10;console.log(a); //true登录后复制let a = null;console.log(a); //false登录后复制 以上就是JS |真与假|的详细内容,更多请关注我的其它相关文章!
标签:console,log,登录,JS,boolean,复制,false From: https://www.cnblogs.com/aow054/p/18423262