returning with &&

后端 未结 3 457
心在旅途
心在旅途 2020-12-04 18:01

What does it mean to return a value with &&?

else if (document.defaultView && document.defaultView.getComputedStyle) {

    // It uses the t         


        
3条回答
  •  时光说笑
    2020-12-04 18:59

    The logical AND operator, &&, works similarly. If the first object is falsy, it returns that object. If it is truthy, it returns the second object. (from https://www.nfriedly.com/techblog/2009/07/advanced-javascript-operators-and-truthy-falsy/).

    Interesting stuff!

    EDIT: So, in your case, if document.defaultView.getComputedStyle(elem, " ") does not return a meaningful ("truthy") value, that value is returned. Otherwise, it returns s.getPropertyValue(name).

提交回复
热议问题