bioneural.net site preferences

Accessibility

Toggle width/ text size:

style

Default/Alternate

Suits visual impairment, mobile devices

Styling

Change the theme:

layout

Sorry, this option is not enabled

Link behaviour

Links with an icon are off-site:

links

Right-click any link to optionally open in a new window or tab


 

Identifying JavaScript errors and warnings

Most hobbyist web developers know how to ensure their (X)HTML, CSS and links are valid. Bloggers can check the validity or their RSS or Atom feeds. Even if your JavaScript knowledge is limited to copy-and-paste (e.g. from JavaScript Source), it's still useful to be able to check that the scripts you are using don't generate errors or warnings.

One means of identifying errors and checking your code for warnings is to use Firefox together with the Web Developer extension. It's worth noting that this multifaceted tool does far more than check for JavaScript errors:

toolbar

The Web Developer extension adds a menu and a toolbar to the browser with various web developer tools. It is designed for Mozilla Firefox and Mozilla, and will run on any platform that these browsers support including Windows, Mac OS X and Linux. The extension is highly configurable and contains many powerful features including CSS manipulation, multiple validation options and tools to display information about the current page.

A similar toolbar exists for Windows IE users.

With the Web Developer extension installed, as a page loads an icon indicates the presence of any errors:

errorred

... or warnings:

warnyella

Clicking on the red icon gives you details about the error, opening the built-in JavaScript Console:

errors

Likewise, clicking on the yellow icon offers details about warnings:

warnings

The option to show strict JavaScript warnings is enabled from the Options drop-down menu in the Web Developer Toolbar:

enable

The error "assignment to undeclared variable XXX" seems to be very common in copy-and-paste JavaScript, but it is easy to find information on how to fix these warnings. Of course warnings generated by referenced third-party JavaScripts, such as those used by Google AdSense, cannot be so easily be addressed. Some AdSense-related warnings pertained to the script in my pages e.g. "asignment to undeclared variable google_ad_client", which I could fix by adding:

var google_ad_client;

Other warnings relate to:

  • asignment to undeclared variable google_XXX
  • reference to undefined property w.google_XXX
  • function ga does not always return a value

As such warnings apparently slow down script execution I e-mailed AdSense to see if they have plans to fix their code. They replied to say:

We have forwarded your findings onto our team for further investigation. Although we designed our ad code to be as easy to use and execute as possible, there are certain limitations inherent with some browsers.

Hmm... a browser problem? Clearly no comprehension of the issue.

3 responses to Identifying JavaScript errors and warnings


  1. 1 jeffry

    Bruce, thanks for informing me about that.

    OK, so it's not related. I thought some Java programmers are normally having Java coffee while creating something.

  2. 2 Bruce

    Jeffry, if you mean the mobile buttons yes they work using Safari, although they are not easy to click. It's a bit like that fairground game where you try to clobber snakes as they pop out of their holes... not an ideal interface IMHO.

    The origin of the term "Java" (programming language) is unknown; it has been suggested that it stands for Just Another Vague Acronym (see here). In any case, it is not related to JavaScript or the Indonesian island.

  3. 3 jeffry

    I've done some changes and downloaded some javascripts into my template now. Not really sure if it works on Mac.

    Btw, is there any connection between the term Java in Javascript and the other Java term as an island of Indonesia?

Something to say?

Comments may be moderated, are subject to spam filtering, and should be inoffensive and relevant to this post. Please disclose commercial interests.

Usable tags include <a href=""> <blockquote> <em>.