Faster, Higher, Stronger
更快,更高,更强

? in JavaScript

While reading JavaScript codes, you may find “?” operator in a high frequency.

(condition) ? truePart : falsePart; is rough equivalent of:


if (condition) {
    truePart;
}
else {
    falsePart;
}

The same shorthand method can also be used to set variables. For instance: myNewVariable = (condition) ? trueValue : falseValue; is equivalent to:


if (condition) {
    myNewVariable = trueValue;
}
else {
    myNewVariable = falseValue;
}

赞(0) 打赏
未经允许不得转载:峰间的云 » ? in JavaScript

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏