声明:
(7 hungerLevel <)
は、命令(それはブール文です)のように解釈されます。だからあなたのコード内で2つの部分があり、1つ目はあれば、他の
var hungerLevel = 7.2;
if (hungerLevel > 7) {
console.log("Time to eat"); /* instruction inside the if*/
} else
(hungerLevel < 7) /* instruction inside the else*/
最後の部分は、単にログを印刷している他場合とは何の関係もありません。
{
console.log("Let's eat later");
}
次の2つの出力を持っている理由だからです。我々は単純化した場合、あなたのコードは、そのようなものです:それは出力として文の両方を与えて
var hungerLevel = 7.2;
if (hungerLevel > 7) {
console.log("Time to eat"); /* instruction inside the if*/
} else
hungerLevel < 7 /* instruction inside the else*/
console.log("Let's eat later");
!! – Therebelentropy
実際にはエラーはありません。 –
私が与えたものではありませんが、elseとすれば、正しい出力が得られます。なぜそれが起こりますか? – Therebelentropy