title: JavaScript "x in obj": obj.x is undefined?
body: <p>The following code :  </p>
  
  <pre><code>var obj = {uname:"OdO", age:"22"};  
  alert(obj.uname);
  </code></pre>
  
  <p>results in:  </p>
  
  <pre><code>OdO 
  </code></pre>
  
  <p>Now, using the same concept in a <code>for..in</code> statement :  </p>
  
  <pre><code>for (x in obj) {
      document.write(obj.x+"&lt;br&gt;");
  }
  </code></pre>
  
  <p>I expected it to print the following:  </p>
  
  <pre><code>OdO  
  22 
  </code></pre>
  
  <p>but it prints :  </p>
  
  <pre><code>undefined  
  undefined
  </code></pre>
  
  <p>And to achieve printing looping in the elements, it should be written as an array elements like this:  </p>
  
  <pre><code>for (x in obj) {
      document.write(obj[x]+"&lt;br&gt;");
  } 
  </code></pre>
  
  <p>Then, why the first syntax doesn't work, however it works out of the <code>for..in</code> statement ?</p>