是否可以像这样的语句使用条件运算符?
(x == y) ? alert("yo!") : alert("meh!");
Run Code Online (Sandbox Code Playgroud)
或者使用它来分配这样的值是否更正确?
z = (x == y) ? "yo!" : "meh!";
Run Code Online (Sandbox Code Playgroud)
如果像声明一样使用它是不正确的,那么可以添加多行代码来执行吗?为多行代码使用ifthen和switch语句更正确吗?
(x == y) ? (alert("yo!"), document.write("woot!")) : (alert("meh!"), document.write("blah!"));
Run Code Online (Sandbox Code Playgroud)