Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jshint, eqnull, Use '===' to compare with 'undefined'

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?

like image 242
Sam Selikoff Avatar asked Sep 04 '14 01:09

Sam Selikoff


People also ask

Is null == undefined?

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.

How do you handle undefined and null in JavaScript?

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 .

How do I ignore JSHint warning?

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.

What is difference between null and undefined in JavaScript with example?

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.


1 Answers

Use this option for the same

"-W041": false

like image 108
Manish Puri Avatar answered Sep 30 '22 12:09

Manish Puri