Just a small problem regarding javascript BOM question
<p>The question is this:</p>

<p><b>Create a page with a number of links. Then write code that fires on the window onload event, displaying
the href of each of the links on the page.</b></p>

<p><i>And this is my solution</i></p>

<pre><code>&lt;html&gt;
&lt;body language="Javascript" onload="displayLink()"&gt;
&lt;a href="http://www.google.com/"&gt;First link&lt;/a&gt;
&lt;a href="http://www.yahoo.com/"&gt;Second link&lt;/a&gt;
&lt;a href="http://www.msn.com/"&gt;Third link&lt;/a&gt;

&lt;script type="text/javascript" language="Javascript"&gt;
function displayLink()
{
 for(var i = 0;document.links[i];i++)
 {
 alert(document.links[i].href);
 }
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><i>This is the answer provided by the book</i></p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script language=”JavaScript” type=”text/javascript”&gt;
function displayLinks()
{
 var linksCounter;
 for (linksCounter = 0; linksCounter &lt; document.links.length; linksCounter++)
 {
  alert(document.links[linksCounter].href);
 }
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload=”displayLinks()”&gt;
&lt;A href=”link0.htm” &gt;Link 0&lt;/A&gt;
&lt;A href=”link1.htm”&gt;Link 2&lt;/A&gt;
&lt;A href=”link2.htm”&gt;Link 2&lt;/A&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Before I get into the javascript tutorial on how to check user browser version or model,I was using the same method as the example,by acessing the <code>length</code> property of the <code>links</code> array for the loop,but after I read through the tutorial,I find out that I can also use this alternative ways,by using the method that the test condition will evalute to true only if the <code>document.links[i]</code> return a valid value,so does my code is written using the valid method??If it's not,any comment regarding how to write a better code??Correct me if I'm wrong,I heard some of the people say "a good code is not evaluate solely on whether it works or not,but in terms of speed,the ability to comprehend the code,and could posssibly let others to understand the code easily".Is is true??</p>
