Jshint, eqnull, use '===' to compare with 'undefined'

I apologize ahead of time, I am clearly completely unable to figure out how to configure jshint.

I have this line of code

if ( data == undefined || (typeof data === 'object' && data.length === 0) ) { ... 

jshint underlines first == and says

Use '===' to compare with 'undefined'.

I added /* jshint eqnull:true */ . I thought this was an option. I even see an example here (eqnull search).

What am I missing?

+5
source share
2 answers

Use this option for the same

"- W041": false

+6
source

In Javascript, undefined and null are two different values. Direct comparison of other values ​​with undefined problematic because null == undefined , but typeof null != typeof undefined .

From your comment above, it seems that you explicitly want to check the null and undefined values, in which case you could write (data === undefined || data === null) .

If you want to keep a shorter expression, you can simply write data == null , which is functionally identical. As you mentioned above, you need to provide the option /* jshint eqnull:true */ .

+1
source

Source: https://habr.com/ru/post/1201784/


All Articles