Javascript AND operator within assignment

后端 未结 6 846
滥情空心
滥情空心 2020-11-22 05:20

I know that in JavaScript you can do:

var oneOrTheOther = someOtherVar || \"these are not the droids you are looking for...\";

where the va

6条回答
  •  余生分开走
    2020-11-22 05:58

    Quoting Douglas Crockford1:

    The && operator produces the value of its first operand if the first operand is falsy. Otherwise it produces the value of the second operand.


    1 Douglas Crockford: JavaScript: The Good Parts - Page 16

提交回复
热议问题