【发布时间】:2012-09-27 18:43:09
【问题描述】:
我编写了以下代码:
showTitles = (typeof showTitles !== 'undefined') ? showTitles : 'Y';
showSelectGroup = (typeof showSelectGroup !== 'undefined') ? showSelectGroup : 'Y';
但是 JSLint 说:
警告 3 JS Lint:意外的“typeof”。使用 '===' 直接与 undefined 进行比较。
我应该如何更改我的代码?
【问题讨论】:
-
我对 jslint 一无所知,但我认为它在告诉你这样做:
(showtitles === undefined)。 -
它在消息中说:
Use '===' to compare directly with undefined。 -
Unexpected 'typeof'是问题所在,而不是!==。 -
你最好写
var showTitles = showTitles || 'Y';
标签: javascript jquery jslint