Javascript returns string for OR(||) operation

后端 未结 2 1635
逝去的感伤
逝去的感伤 2021-01-23 11:12

I am unable to understand this.

Following is expression uses OR operator

var subCond1 = adj.getData(\'relationEnabled\') == \'true\' || adj.getData(\'unh         


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-23 11:47

    Javascript returns the first operand that has a truthy value, whatever that truthy value is or the value of the last operand if none before are truthy. That is a designed feature of Javascript (yes it is different than other languages).

    You can turn that into a boolean by comparing to see if it is == true if you want or it is sometimes done with !!.

提交回复
热议问题