title: JavaScript: using typeof to check if string
body: <p>I'm working on a codecademy.com exercise where we use for-in statements to loop through an object and print hello in different languages by checking to see if the values of the properties in the languages object are strings using <code>typeof</code></p>
  
  <p>my check to see if the value is a string is not working. my loops giving me this result</p>
  
  <pre><code>english
  french
  notALanguage
  spanish
  </code></pre>
  
  <p>The code </p>
  
  <pre><code>   var languages = {
          english: "Hello!",
          french: "Bonjour!",
          notALanguage: 4,
          spanish: "Hola!"
      };
  
      // print hello in the 3 different languages
      for(var hello in languages){
          var value = hello;
          if (typeof value === "string"){
          console.log(value); 
          }
      }
  </code></pre>
  
  <p>These are the instructions for the exercise</p>
  
  <blockquote>
    <p>Objects aren't so foreign if you really think about it!</p>
    
    <p>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".</p>
    
    <p>Recall the for-in loop:</p>
    
    <p>for(var x in obj) { executeSomething();  }</p>
    
    <p>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.</p>
    
    <p>Let's combine our knowledge of these two concepts.</p>
    
    <p>Examine the languages object. Three properties are strings, whereas
    one is a number.</p>
    
    <p>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.</p>
  </blockquote>