window.onload=function(){
if(test()&&true){
console.log("hello");
}
console.log(test()&&true);
};
function test(){
}
if(true&&undefined) が false を返すのに、console.log(true&&undefined) が undefined を返すのはなぜですか?
window.onload=function(){
if(test()&&true){
console.log("hello");
}
console.log(test()&&true);
};
function test(){
}
if(true&&undefined) が false を返すのに、console.log(true&&undefined) が undefined を返すのはなぜですか?
if(true&&undefined)何も返しません。-expressionは引数と同様にAND評価 true&&undefinedされ、偽の値であるため、if ステートメントの本体は実行されません。undefinedconsole.logundefined
演算子を使用する&&と、最初の falsey 値が返されます。
undefinedは falsey であるため、ステートメントifは false と評価されます。