<body>
<script>
var a = 20;
var b;
if (a > 10) {
b = 100;
} else {
b = 200;
}
alert("b=" + b);
// 三元表达式,可以简化基本的if-else语句结构
var c = a > 10 ? 100 : 200;
alert("c=" + c);
// 三元表达式,也可以简化复杂的if-else语句结构
var d = a > 20 ? 200 : a > 10 ? 100 : 300;
alert("d=" + d);
</script>
</body>
12-14
5万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-04
188
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-30
142
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)