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.