Categories:

Tip 3: Understand the cost of your objects

The fact is, some JavaScript objects are less forgiving on the browser than others. While recognizing exactly which isn't easy (and isn't the goal here), just becoming aware of this fact is important.

Take, for example, these two properties:

-object.innerText //IE only
-object.innerHTML

Did you know that the second property demands multiple times the system resources to call than the first? If all you're changing is the textual content of a <div> or <span> and in IE only, innerText would definitely be the more efficient choice. Another example are the CSS properties "display" and "visibility"; the former is significantly more expensive than the later.

In conclusion

Many would agree that it's just a matter of time now before JavaScript eventually graduates to become a full blown language like C or Java. Practicing responsible and efficient coding now can save you a lot of work in the future...you have been warned!