Freecodecamp: Comparison with the Strict Equality Operator - Difference between "==" and "===" wording

Created on 16 May 2017  路  11Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Comparison with the Strict Equality Operator has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


// Setup
function testStrict(val) {
  if (val) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

// Change this value to test
testStrict(10);

The explanation for the difference between "==" and "===" is incorrect. They both test for the data type of the compared elements, but "===" does not allow the elements to be converted to other data types if they are not the same, where as "==" (a.k.a. coercion), does allow the elements to be converted.

help wanted discussing

Most helpful comment

I agree with @dhcodes, however, I think there should be another module added for users to implement with the equality operator (==) and the strict equality operator (===) in the same module to hit home the difference. I think that would be a good place for @dhcodes example. Right now you learn and practice with them separately and it would be good to have a module that you are required to use both to make sure you understand the difference between them.

These links may also be helpful to include for the new said module. They are directly from the Ecmascript Specification website:
== Equality Algorithm ( http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 )
=== Strict Equality Algorithm ( http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6 )

@dakshshah96 I think your description is sufficient. The only update I think I may make is to say 'data type' instead of 'type' to match the wording used in the modules.

All 11 comments

Agreed.

Reference https://developer.mozilla.org/en/docs/Web/JavaScript/Equality_comparisons_and_sameness

Opening up for suggestions in the verbiage that's simple enough to explain the correct difference.

/cc @freeCodeCamp/moderators

@raisedadead How does this sound?

The == operator will compare for equality _after doing any necessary type conversions_. The strict equality operator (===) will not do the conversion, so if two values are not the same type, === will simply return false.

I think in addition to what @dakshshah96's suggestion, what really helps with this concept are examples. Something like:

typeof 3 // return 'number'
typeof '3' // returns 'string'

3 == '3' // returns true because Javascript is doing a type conversion on the string
3 === '3' // returns false because strict equality does not allow the type conversion and as demonstrated in the first two lines of code, 3 is a type of 'number' but '3' is a type of 'string'

I agree with @dhcodes, however, I think there should be another module added for users to implement with the equality operator (==) and the strict equality operator (===) in the same module to hit home the difference. I think that would be a good place for @dhcodes example. Right now you learn and practice with them separately and it would be good to have a module that you are required to use both to make sure you understand the difference between them.

These links may also be helpful to include for the new said module. They are directly from the Ecmascript Specification website:
== Equality Algorithm ( http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 )
=== Strict Equality Algorithm ( http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6 )

@dakshshah96 I think your description is sufficient. The only update I think I may make is to say 'data type' instead of 'type' to match the wording used in the modules.

@jbosman @dhcodes awesome! 100% agreed. We could have more than one challenge on this if necessary to really drive home the point. Would either of you be interested in creating these challenges?

Looks like this is available, I'll take it up. It would be a nice introduction to creating new challenges.

@Manish-Giri Awesome - thanks! Let me know if I can be of any help :)

@QuincyLarson Can I take up this issue ? I'm really interested to work on this as I'm a beginner

@Manish-Giri Have you had time to look into this? If not, could we let @ajomadlabs take a crack at it?

@QuincyLarson Oops, sorry - this is on the way, just need to make some changes and push it.

Was this page helpful?
0 / 5 - 0 ratings