`
san_liuhongbin
  • 浏览: 20374 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

| | 的用法

阅读更多

When used with Boolean operands, the || operator performs the Boolean OR operation on the two values: it returns true if either the first operand or the second operand is true, or if both are true. If both operands are false, it returns false.

    All know the above usage, but I mention the following usage:

An idiomatic usage of this operator is to select the first value in a set of alternatives that is defined and non-null (that is, the first value that does not convert to false). Here is an example:

// If max_width is defined, use that.  Otherwise look for a value in
// the preferences object.  If that is not defined use a hard-coded constant.
var max = max_width || preferences.max_width || 500;

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics