For the past few months I've been working with javascript and Jquery. It isn't my first experience with javascript, but it is my first experience in an enterprise setting and that does change things a bit.

This is a brief, unorganized collection of some of the initial lessons I've learned while working with javascript.

  • Javascript will destroy you if you don't have a proper development environment. The language is designed to be extremely fault tolerant and it succeeds in that goal. Problem is that it makes developing and debugging in it a pain. When faced with a syntax error, javascript doesn't always output an error as sensible languages do. Instead sometimes it will swallow the error and the function containing it entirely and do nothing. Very frustrating.

  • Javascript should be at the bottom of any file. A common rule, but I learned why this is. When the browser encounters javascript it will postpone DOM processing until it's parsed and executed the javascript. This is because the javascript may affect the existing elements on the page. So if a large javascript library (like jquery) was placed before any HTML, nothing would be shown until this library had been parsed and executed. Users might think the site was broken and abandon the page.

  • It is easy to get a very messy structure that makes getting an overview of the codebase really hard. Great care must be taken with names, repetition and general structure to ensure the maintainability of a project.

  • Just because it works on your machine doesn't mean it works on everybodys machine. Different browsers have differing capabilities. Ensuring you don't use functionality not available on all browsers you target is both importment tricky. This is doubly true for the browsers on mobile devices.

  • Chrome dev tools are very useful for debugging.