var eatsPlants = true;
var eatsAnimals = false;
var category = eatsPlants ? (eatsAnimals ? "omnivore" : "herbivore") : (eatsAnimals ? "carnivore" : "undefined");
console.log(category);Run Code Online (Sandbox Code Playgroud)
//我不明白它是如何检查多个事物的代码
小智 6
var category = eatsPlants ? (eatsAnimals ? "omnivore" : "herbivore") : (eatsAnimals ? "carnivore" : "undefined");
Run Code Online (Sandbox Code Playgroud)
嗯,这和
if(eatsPlants)
if(eatsAnimals) category = "omnivore";
else category = "herbivore";
else
if(eatsAnimals) category = "carnivore";
else category = "undefined";
Run Code Online (Sandbox Code Playgroud)
该条件运算符的结构如下:
if(eatsPlants)
if(eatsAnimals) category = "omnivore";
else category = "herbivore";
else
if(eatsAnimals) category = "carnivore";
else category = "undefined";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |