【发布时间】:2011-08-26 09:43:01
【问题描述】:
我想知道 javascript 中 if 的简码是什么?
就像在 php 中一样:
$res = ($x > $y)? $x: $y;
它在javascript中的转换是什么?
【问题讨论】:
-
hm...没注意到...它是一样的...thnx all
-
您无需更改任何内容:上面的 PHP 代码已经是有效的 JavaScript。
$res = ($x > $y)? $x: $y;(可以在变量名中使用$) -
当你不知道构造的名称时会发生这种情况,他称它为
shortcut if,如果你搜索它,你将找不到任何重复。我正在重置其中一张反对票。
标签: javascript if-statement shortcut conditional-operator