43

How can I stop the error message Expected '===' and instead saw '=='. from appearing in jslint. Doesn't seem to be an option.

usertest
  • 27,132
  • 30
  • 72
  • 94

5 Answers5

42

For those using JSHint, you can turn off this warning by setting the option eqeqeq to false in your JSHint options (usually .jshintrc)

"eqeqeq": false

From the documentation: http://jshint.com/docs/options/#eqeqeq

Edit:

If you want to be a good citizen and fix your code to use the recommended comparison instead of turning the warning off, make sure both sides of the comparison are using the same type.

For example:

"123" == 123          // true, I'm lazy and JSHint hates me
"123" === 123         // false, no love
Number("123") === 123 // true, no warning
bubbassauro
  • 3,969
  • 2
  • 45
  • 45
11

This is pretty hot off the press.

Douglas Crockford has just added an 'eqeq' option to the JSLint tool.

See one of the June 12, 2011 edits on GitHub:

https://github.com/douglascrockford/JSLint/commits/2e8d430b5b9543caefb3743513181f1295f52ddf/jslint.js

Ad the time of writing it hadn't been updated on the JSLint front page, but i've tested it with the following and get no == related warnings:

/*jslint eqeq: true*/
var x = 0;
if (x == 1) {
    alert("test");
}
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
8

Although its late its worth, it would help some one who is in need

To disable use -

/* eslint eqeqeq: 0 */

To make it as warning use -

/* eslint eqeqeq: 1 */
Pradeep Potnuru
  • 750
  • 6
  • 13
  • Worked! I got this error from within Visual Studio: `eqeqeq (ESlint) Expected '!==' and instead saw'='` and this fix worked like charm! – Noble Jan 10 '20 at 17:56
  • 1
    As a note, this goes at the top of the .js file you want to suppress. – BeanFlicker Apr 18 '20 at 17:27
4

You are correct that there is no option for that. The only way is to either use === or modify the source code. I almost always use === anyway. It's better in general unless you know that == is really what you want.

Matthew Crumley
  • 101,441
  • 24
  • 103
  • 129
  • 4
    except when comparing to null: `some == null` returns `true` if `some === undefined` or `some === null`, wich may be usefull. – KooiInc Jun 11 '11 at 19:15
  • Sas just about to say the same as @Koolinc. `== null` is the only valid use case for `==` . There are plenty of use cases for `if(value)` without the check. – Raynos Jun 11 '11 at 19:15
  • @Koolinc Yes, there are cases where it's useful, but I use `===` by default. – Matthew Crumley Jun 11 '11 at 19:17
  • 3
    @Raynos: Why the hate for `==`? If you know what you're doing, there's no problem with using it. JSLint not providing an option to turn that warning off is taking opinionatedness a step too far. – Tim Down Jun 12 '11 at 00:40
  • @Tim I agree there's no problem if you know it's what you want, and it would be nice if JSLint had that option. When I've used JSLint (I don't normally), I just ignored the warnings when I knew I had a good reason to. – Matthew Crumley Jun 12 '11 at 02:39
0

same error show me I can fix by using this way

status.user_profile.toString() === props.props.id.toString() 

I'm using react js give example I'm using something like that

id = 1

if I excess params show me like this

params :{ id:"1" }

If I excess this way

id == params.id // output true

If I excess this way

id === params.id // output false

because not 100% eqality so show me error in terminal

Expected '===' and instead saw '=='

So I can think about and fix it by converting same data type like this

id.toString()  === params.id.toString()  // return true
Kashif
  • 1,364
  • 17
  • 21
  • While this answer works, it really does not scale well and I dont see the point of the warning especially with most use cases as most database ids are integers (which may be a number or a string) it helps to loosely check them – Malik Bagwala Jul 13 '20 at 08:20