== versus ===


#1

I learned Python before JavaScript, so I instinctively typed == instead of === on the third operation. It worked. What I want to know is whats the difference between == and ===


#2

Hello There @dbprojectcomcast.net. So what your comparing here is

The strict equality operator VS The lenient equality operator

Strict Equality Operator(===)


The strict equality operator is basically have to have the same value type... So it basically checks if the types are same AND They have the same value...
So...

if(43==='Something'){

}
else{
console.log("Not Equal")
}

Thats basically gonna log Not Equal. Because its not the same data-types... And it also checks if it is the same value after checking it has the same data-type
So...

if(5===5){
console.log("Good")
}

So the above code is gonna log Good. Because it is the same data-type and actual value...

Lenient equality operator(==)


Basically the same as the strict equality operator but it dosent check for the data-types of the two values bieng compared. And that is likely to give you some unexpected results....

Conclusion/Recomendation


Your use from == and === depends upon your needs in your program. Thats for you to decide. If you want to learn more go here.


What is wrong with this code? Everytime I run it, the debugger says:Oops! try again, tryDid you remember to put in the 'yes' answer option
What is wrong with this code? Everytime I run it, the debugger says:Oops! try again, tryDid you remember to put in the 'yes' answer option
7: search for a friend (question on why it works)
#3

Whoa. Can you help me with if/else statements?


#4

What exactly is your problem @boobear87 ?


#5

All of if/else. How exactly do you type it?


#6

If-else syntax is as follows:

if (condition) {
//Statements
}
else {
//Statements
}

#7

Thank you, but what about the second "else"?


#8

Do you mean an else-if?

if (condition) {
//Statements
}
else if (condition) {
//Statements
}
else {
//Statements
}

#9

yes thank you very much.