<分区>
我需要检查 auth.runtime.status
是否等于 200,但是 auth.runtime
是不安全的,在 nodejs 中是否有更优雅的方法
if (auth.runtime) {
if (auth.runtime.status == 200 && auth.application.status == 200)
...
}
}
有没有更好的写法?
让我们假设我有更多的嵌套如果
<分区>
我需要检查 auth.runtime.status
是否等于 200,但是 auth.runtime
是不安全的,在 nodejs 中是否有更优雅的方法
if (auth.runtime) {
if (auth.runtime.status == 200 && auth.application.status == 200)
...
}
}
有没有更好的写法?
让我们假设我有更多的嵌套如果
最佳答案
你可以拿optional chaining operator ?.
使用单个 if
语句。
if (auth.runtime?.status == 200 && auth.application.status == 200)
关于javascript - 在 JavaScript 中避免嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62260540/