Jump to content

omnescient

Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • Gender
    Female
  • Location
    UK

omnescient's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Yes, valid point, although if people are researching node list navigation, they are probably beyond the javascript 'beginner' level. Assigning the length of a node list to a variable before loop criteria are evaluated doesn't seem particularly complicated in that context. With regard to loops generally, it is possible to create unintentional infinite loops if the length is evaluated on each iteration, rather than once only before the loop is run, as in the scenario suggested by justsomeguy.
  2. Thanks for that Foxy; I didn't see that mentioned on the page to which I referred. However, I'd have thought that encouraging beginners to adopt 'best practice' might itself be regarded as 'best practice' for the tutorials? My post related to consistency of information and advice offered on the site.
  3. In a javascript for loop, I don't believe comma-separated multiple variables each require the 'var' keyword to be stated, just the first. I can see what you're saying about the dynamic array length, or in this case the node list length. Perhaps the javascript performance example is too simplistic without an appropriate caveat.
  4. For example, here: http://www.w3schools.com/js/js_performance.aspJavaScript PerformanceReduce Activity in loopsBad Code:for(i - 0; i < arr.length; i++)Better Code:l = arr.length;for(i = 0; i < l; i++)The bad code accesses the length property of an array each time the loop is iterated.The better code accesses the length property outside the loop, and makes the loop run faster. But an example here: http://www.w3schools.com/js/js_htmldom_nodelist.asp JavaScript HTML DOM Node ListHTML DOM Node List LengthThe length property is useful when you want to loop through the nodes in a node list:ExampleChange the background color of all <p> elements in a node list: var myNodelist = document.getElementsByTagName("p");var i;for (i = 0; i < myNodelist.length; i++) { myNodelist[i].style.backgroundColor = "red";}is inconsistent with that advice.// for (var i = 0, j = myNodelist.length; i < j; i++) { ? }
  5. I believe that one is only displayed at midnight.
×
×
  • Create New...