简单的问题。javascript中是否存在类似php的东西???
在 php 中你可以这样做condition ?? statement2
这与 相同condition? condition : statement2。
javascript中有类似的东西吗?
我会使用逻辑或运算符 ( ||)
console.log("true value" || "other")
console.log(false || "other")Run Code Online (Sandbox Code Playgroud)
这是有效的,因为(来源):
expr1 || expr2expr1是否可以转换为true则返回;否则,返回expr2