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 compare 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?
It means null is equal to undefined but not identical. When we define a variable to undefined then we are trying to convey that the variable does not exist . When we define a variable to null then we are trying to convey that the variable is empty.
The typeof operator for undefined value returns undefined . Hence, you can check the undefined value using typeof operator. Also, null values are checked using the === operator. Note: We cannot use the typeof operator for null as it returns object .
Yes, there is a way. Two in fact. In October 2013 jshint added a way to ignore blocks of code like this: // Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */ // Code here will be linted with JSHint.
Unassigned variables are initialized by JavaScript with a default value of undefined. Here as the variable is declared but not assigned to any value, the variable by default is assigned a value of undefined. On the other hand, null is an object. It can be assigned to a variable as a representation of no value.
Use this option for the same
"-W041": false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With