7/8: why ===?


#1

After staring at my code in bewilderment for a while, I changed the line
if (friends[k].firstName == name) {
to
if (friends[k].firstName === name) {

Suddenly, it worked. Now I assume this is teaching a best practice of some sort, because the == worked when I ran it straight through firefox?


#2

Hello :smile:
For you to know the difference:
== means equal to.
=== means equal and identic to.
What's the difference?
If you do 5==5 you will get true, as well with '5===5'. If you do 5=="5" you will also get true. However, when you do 5==="5" you will get false.
Why?
5 is equal to 5, but when one of the values is a string and the other is a number, the types are different. === will check for both type and value. When you try 5==="5", the value might be the same, but the type is not, therefore, it returns false.
Hope this helps so you can understand why that happened in your code. As I miss access the rest of the code, I don't know why something is now working, but I hope you can find out with this info :smile: