JavaScript三元运算符嵌套使用


第一种嵌套情况

false?'true':true?'t':'f'  //t
false?'true':false?'t':'f'  //f

第二种嵌套情况

true?true?'a':'b':'c'  //a
true?false?'a':'b':'c'  //b
false?false?'a':'b':'c'  //c
var display_state = (state == null ? "未用" : (state == true ? "在用" : "停用"))

相关