admin管理员组文章数量:1316336
I apologize ahead of time, I am clearly utterly incapable of understanding how to configure jshint.
I have this line of code
if ( data == undefined || (typeof data === 'object' && data.length === 0) ) {
...
jshint is underlining the first ==
and saying
Use '===' to pare with 'undefined'.
I added /* jshint eqnull:true */
. I thought this is what the option does. I even see an example here (search for eqnull).
What am I missing?
I apologize ahead of time, I am clearly utterly incapable of understanding how to configure jshint.
I have this line of code
if ( data == undefined || (typeof data === 'object' && data.length === 0) ) {
...
jshint is underlining the first ==
and saying
Use '===' to pare with 'undefined'.
I added /* jshint eqnull:true */
. I thought this is what the option does. I even see an example here (search for eqnull).
What am I missing?
Share Improve this question edited Nov 20, 2015 at 21:26 Jonatas Walker 14.2k6 gold badges57 silver badges82 bronze badges asked Sep 4, 2014 at 1:40 Sam SelikoffSam Selikoff 12.7k13 gold badges60 silver badges107 bronze badges 5-
eqnull
suppresses the warning about paring withnull
, notundefined
. – Barmar Commented Sep 4, 2014 at 1:49 -
Is it possible to suppress the warning about
undefined
? – Sam Selikoff Commented Sep 4, 2014 at 1:50 - I don't see any mention of such a thing in the documentation. – Barmar Commented Sep 4, 2014 at 1:50
- If you use " typeof data == 'undefined' " instead of " data == undefined ", no warning message will be shown. You don't need to suppress warning when no warning is displayed. – Fumu 7 Commented Sep 4, 2014 at 2:09
-
I'd like to use
== undefined
to coerce null to undefined.typeof null
is object. – Sam Selikoff Commented Sep 4, 2014 at 2:19
2 Answers
Reset to default 6Use this option for the same
"-W041": false
In Javascript, undefined
and null
are two distinct values. Directly paring other values to undefined
is problematic, because null == undefined
, but typeof null != typeof undefined
.
From your ment above, it seems that you explicitly want to check for both null
and undefined
values, in which case you could write (data === undefined || data === null)
.
If you are keen to keep a shorter expression, you could just write data == null
, which is functionally identical. As you mention above, you will need to provide the /* jshint eqnull:true */
option.
本文标签: javascriptjshinteqnullUse 3939 to compare with 39undefined39Stack Overflow
版权声明:本文标题:javascript - jshint, eqnull, Use '===' to compare with 'undefined' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742004353a2411657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论