is there anything like (1==0 ? "no" : "yes") in javascript?
在javascript中有什么类似的(1 == 0?“no”:“是”)?
3 个解决方案
#1
JavaScript has the conditional operator, so it's perfectly legitimate to do:
JavaScript具有条件运算符,因此完全合法:
var response = (1 == 0 ? "no" : "yes");
#2
yes, exactly as you wrote it :)
是的,正如你写的那样:)
#3
Yes - it's the conditional operator, and the syntax is exactly as you've written it.
是的 - 它是条件运算符,语法与您编写的完全一样。
#1
JavaScript has the conditional operator, so it's perfectly legitimate to do:
JavaScript具有条件运算符,因此完全合法:
var response = (1 == 0 ? "no" : "yes");
#2
yes, exactly as you wrote it :)
是的,正如你写的那样:)
#3
Yes - it's the conditional operator, and the syntax is exactly as you've written it.
是的 - 它是条件运算符,语法与您编写的完全一样。