简体   繁体   English

无法弄清楚三元条件语句

[英]Can't figure out ternary conditional statement

I'm having some trouble figuring out this statement:我在弄清楚这个陈述时遇到了一些麻烦:

return this.savedValue ? 
        this.currentValue ? 
        this.currentValue : this.savedValue
        : this.currentValue

How would that look like in classical if else statement这在经典的 if else 语句中会是什么样子

For a better understanding you could write:为了更好地理解,你可以写:

return this.savedValue
 ? (this.currentValue ? this.currentValue : this.savedValue)
 : this.currentValue   

if (this.savedValue) {
  if (this.currentValue) {
    return this.currentValue;
  }
  else {
    return this.savedValue;
  }
} else {
  return this.currentValue;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM