Debugging

I just spent an hour or so debugging some JavaScript.

The code was simple, concatenate a string to form a selector: '#in-category-' . termId. Undefined. Always undefined.

I started dumping all sorts of things in the console to debug. termId was defined. The code was passing through conditional statements correctly.

I was just about to send the diff to my work mate Dzikri with the note “this is the general idea but I’ve made a silly mistake” when I saw it.

I was using PHP style concatenation in JavaScript.

I’ve noticed this immediately in people’s code. I’m sure you did too.

By Peter Wilson

Peter has worked on the web for twenty years on everything from table based layouts in the 90s to enterprise grade CMS development. Peter’s a big fan of musical theatre and often encourages his industry colleagues to join him for a show or two in New York or in the West End.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.