Why number 4 is printed?



Oops, try again. It looks like you printed 4 when you shouldn't have!

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

// print hello in the 3 different languages
for(var prop in languages){
    if(typeof prop === "string"){


The above is checking the key name, not the associated value, hence all values are logged out.

if (typeof languages[prop] === 'string')

In JavaScript objects, all key names are strings.


Thank you very much!!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.