Proper use of ||

前端 未结 3 1140
故里飘歌
故里飘歌 2020-12-03 23:04

The general question I suppose is: when does || return the item on the left, and when does it return the item on the right?

The specific question, is why doesn\'t t

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 23:49

    It returns the first true from the left. If no true it returns false. If the expressions resolve to true, in case of a Boolean or a non-zero or non-null or non-undefined value.

    Edit:

    Yes, the value has to be truthy...not only true.

提交回复
热议问题