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

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

I coded the following:

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


        
3条回答
  •  生来不讨喜
    2021-01-11 09:56

    This message reflects the latest best practices. As of ES5 strict mode, the global value of undefined can no longer be changed and a direct comparison is simpler code and faster. In short, JSLint is aware of all this, and is giving you good advice.

    In this case, change typeof showTitles !== 'undefined' to showTitles === undefined.

提交回复
热议问题