Introduction to Objects II
Looks For-In To Me

Objects aren't so foreign if you really think about it!

Remember you can figure out the type of a variable by using typeof myVariable;. Types we are concerned with for now are "object", "string", and "number".

Recall the for-in loop:

for(var x in obj) {

This will go through all the properties of obj one by one and assign the property name to x on each run of the loop.

Let's combine our knowledge of these two concepts.


Examine the languages object. Three properties are strings, whereas one is a number.

Use a for-in loop to print out the three ways to say hello. In the loop, you should check to see if the property value is a string so you don't accidentally print a number.

Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

You should use an if statement in combination with the typeof operator to figure out whether or not something is a "string". If it's a "string", then print it!

Make sure you're checking the property value (e.g., "Hello!") and not the property name (e.g., english). Recall that if we save a property name to a variable, we can access the value associated with that name using bracket notation. See here to review this.


Learn more advanced JavaScript in our new AngularJS course!