JS -真與假-

aow054發表於2024-09-20
真值和假值:在 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 |真與假|的詳細內容,更多請關注我的其它相關文章!

相關文章