O'Reilly logo

JavaScript Cookbook, 2nd Edition by Shelley Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Preliminary Testing and Accessibility

Best developer practices run the gamut from keeping the cruft out of your code to ensuring your code is accessible to all your application or site’s users. In this chapter, I’m focusing on two specific components: prelimary testing and accessibility.

There are various forms of testing, including running tools that highlight bad practices, unit testing, performance testing, as well as testing your applications in a variety of environments.

Regardless of how well the code tests out, if it isn’t accessible to all your audience, then it fails. At the end of the chapter, we’ll look at a couple of approaches you can take to ensure your code is accessible as well as accurate and efficient.

Cleaning Up Your Code with JSHint

Problem

You want to check your code for any gotchas that may not trigger a failure, but also aren’t the best coding practices.

Solution

Use a lint tool such as JSHint to highlight potential problems or less than optimal code.

Discussion

The simplest approach to ensuring your code meets a minimum standard of acceptable coding standards is to use the strict setting at the beginning of your code or function:

'use strict';

This setting ensures certain programming standards are met, such as always defining variables, and never using eval(). And of course, the most reliable way of ensuring your code meets standards is whatever error mechanism is built into the tools you’re using to run the code, typically explored in depth using your favorite ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required