[英]Does EcmaScript have “reverse if notation”?
The normal way to write an if
-statement is编写
if
语句的正常方法是
if (a == b) {a=1}
but in eg.但在例如。 Perl it is possible to write the same as
Perl 可以这样写
a=1 if (a == b)
Is a similar syntax possible with EcmaScript? EcmaScript 是否可以使用类似的语法?
There is not a specific statement to do that.没有具体的声明可以做到这一点。 You still have several options though
不过,您仍然有多种选择
if (a == b) {
a = 1
}
if (a == b) a = 1 // No parenthesis
a == b ? a = 1 : null // Using ternary operator
a = a == b ? 1 : a // Using ternary operator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.