Just because it makes no significant difference to run times does not mean that there is no point in applying optimisations to javaScript.
Where the optimised version is just as quick to write and just as easy to read as the unoptimised version then using the optimised version still makes sense.
Where the optimised version results in less typing and easier to read code then there is even less reason for using the alternative.
Often using a slightly better optimised version means that you are using code that is easier to read and maintain.
There are of course also a lot of optimisations that would make the code run slightly faster but which make the code far harder to read and understand - these should always be avoided as readability is far more significant than speed with JavaScript.
So for example I'd reference the first data row in a table using:
Code:
document.getElementsByTagName('table')[0].tBodies[0].rows[0]
rather than
Code:
document.getElementsByTagName('table')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0]
because it is shorter to type and easier to read and the fact that the shorter version is actually a more efficient way to do the access iin most modern browsers is an added benefit rather than a reason.
Bookmarks