27 (Looks for-in to me); ==, ===, or =


#1

var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};

// print hello in the 3 different languages
for (var x in languages) {
if (typeof languages[x] == "string") {
console.log(languages[x]);
} else {
console.log(" ");
}
};

Above is my code. It works, but I was messing around with it and realized that "==" and "===" work, but "=" does not (referring to the if/else statement).
I know that == vs. === differentiate between equal and equal exactly, I think as in type and content, but why wouldn't a single "=" sign work in this case?


#2

HI I think that = don't work because is use to Store thing into variable


#3

wizmarco is right. the '=' is an assignment operator. It's used to assign something, not compare it.


#4

One = sign would be assigning a variable.
== or === are operators for comparison