Codeclimate : JSLint : Expected ‘===’ and instead saw ‘==’, How to pass analyzer

If you check your JS code using JSLint then it generally shows warning messages like

Expected '!==' and instead saw '!='.
Expected '===' and instead saw '=='

It is found that every suggestions it make are subject to risks. These suggestions are not considered to be followed exactly.

  • Expected ‘===’ and instead saw ‘==’. (Line 64)
    if ($('#referers_cell_number').val == '') {
    
  • Missing semicolon. (Line 75)
    })
    
  • Expected ‘!==’ and instead saw ‘!=’. (Line 83)
    if (addressid != '') {
    
  • Expected ‘!==’ and instead saw ‘!=’. (Line 90)
    if (data != null) {
    
  • Expected ‘===’ and instead saw ‘==’. (Line 93)
    if (refId == '' || typeof(refId) == "undefined") {
    

However, there is a different way to follow these suggestions… like this

The == and != operators do type coercion before comparing. This is bad because it causes ' \t\r\n' == 0 to be true. This can mask type errors.

When comparing to any of the following values, use the === or !== operators (which do not do type coercion): 0 '' undefined null false true

If you only care that a value is truthy or falsy, then use the short form. Instead of

(foo != 0)

just say

(foo)

and instead of

(foo == 0)

say

(!foo)

The === and !== operators are preferred.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s