27. Look for/in me loop -- why does this work?


#1

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

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

isn't string already defined in javascript? why do i need to put it in quotations as "string" in the if statement?


#2

@blogsolver70882,
Read
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Operators/typeof
to have an idear of the =returned Value= of the typeof method.....

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html
http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1