Blog

0 comments

8 things I wish I knew before I started writing Javascript

  (2007-09-13 00:00:00)
  by Simon Lang

This article leans towards the more technical audience, but should be of interest to anyone who wants to use Javascript to give their site a bit more of an interactive feel.

1. The web is littered with many BAD examples

First and most importantly: Don't trust the first Javascript example that pops up in a Google search. Chances are it uses invalid HTML, teaches bad habits and is probably not even written that well. Which leads me to my second tip....

2. Get a proper resource

With a good source of tutorials (such as a book), and a solid up to date reference, you are all set to start writing Javascript the proper way. A few resources I have found invaluable to learning are: w3schools js reference, Sitepoint and Quirks Mode.

3. Get a great debugging tool

In my early days of writing Javascript I would often sit and scratch my head wondering "where the hell are the compiler errors?". Writing in an interpreted language (and one that gets interpreted differently by different browsers at that!) can be a bit of a change if you are more used to compiled languages. Get yourself a tool like Firebug and it will not only make it crystal clear where you are going wrong, but make fixing it even easier.

4. Use an existing library

Whatever you plan on doing with your Javascript - chances are someone has already done it. Check out some of the great, easy to use libraries out there. My favourites are jQuery and mootools but there are plenty more out there.

5. Use a code verifier

Even though Javascript seems like a very forgiving language, good coding practices still apply! Don't fall into bad habits: try verifying all the code you write using a tool like JSLint.

6. Learn to use the DOM

The Document Object Model may seem a little bewildering at first, but once you understand it, it makes modifying your HTML/XML documents a lot easier. w3schools has a good DOM reference for beginners.

7. Ensure you have a firm understanding of what Client side actually means!

Never ever use javascript for password protection. This is not a server-side language and that means your code can easily be viewed and modified by anyone. I am often amazed by the amount of IT professionals who do not understand this distinction.

8. Understand what graceful degradation means, and live by it.

If your website can not work without Javascript you should seriously have a rethink. Sure, only 1% of your target market may have browsers that don't support Javascript - but if you average sale is worth a few thousand dollars losing even one potential customer because they can't see your website is a pretty devastating loss.

0 comments - Leave a comment