Why does JSLint tell me to use “=== undefined” instead of “typeof … === 'undefined'”?

后端 未结 3 1152
日久生厌
日久生厌 2021-01-11 09:46

I coded the following:

showTitles = (typeof showTitles !== \'undefined\') ? showTitles : \'Y\';
showSelectGroup = (typeof showSelectGroup !== \'undefined\')          


        
3条回答
  •  无人及你
    2021-01-11 10:07

    Note that whether this is best practice in general is debatable, but if you want to make it work with JSLint, you could do this

    showTitles = (showTitles !== undefined) ? showTitles : 'Y';
    

提交回复
热议问题