question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
jbosmancommented, May 17, 2017

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.

2reactions
dhcodescommented, May 17, 2017

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'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Strict equality (===) - JavaScript - MDN Web Docs
The strict equality (===) operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality ......
Read more >
Javascript – Equality (==) Operator VS Strict Equality ...
When using strict equality (===) to compare two operands there is no conversion on any of the operands. This is also known as...
Read more >
Difference between == and === Equal Operator in JavaScript
3) While comparing variable using strict equality operator in Java, two object are strictly equal to each other if both are of same...
Read more >
Difference Between =, ==, and === in JavaScript [Examples]
=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar...
Read more >
JavaScript Comparison Operators: Loose Equality (==) vs ...
Loose equality and strict equality operators are totally different from each other. It depends on you to choose which type is best suited...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found