Using NaN instead typeof


#1

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

// print hello in the 3 different languages
for(var property in languages){
if(languages[property]===isNaN(languages[property]))
{console.log(languages.property)
};
}

Why is this code not executable in the quoted exercise "Looks For-In To Me"?


#2

@luvsin,

If you run this code

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

// print hello in the 3 different languages
for(var property in languages){
     console.log(property + " isNan() " +isNaN(languages[property]) );
     // if (languages[property]===isNaN(languages[property])) {
     //        console.log(languages.property)
     // };
 }

and read
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
you will know that you will have to change your IF condition.


#3

thanks! @leonhard.wettengmx.n, now I understand the function of NaN() better .