[removed] || instead of IF statement - is this legal and cross browser valid?

后端 未结 10 969
忘掉有多难
忘掉有多难 2020-12-23 20:43

It seems that:

if (typeof a == \'undefined\') {
    a = 0;
}

and

(typeof a != \'undefined\') || (a = 0)

h

10条回答
  •  鱼传尺愫
    2020-12-23 21:15

    Moreover I suppose it would impact performances because

    (typeof a != 'undefined') || (a = 0)
    

    is composed of two test (even if we don't care about the second one).

    Whereas

    if (typeof a == 'undefined') {
        a = 0;
    }
    

    contains only one test

提交回复
热议问题