|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 7 of 7
In the following error messages, xyz denotes variable text that JavaScript provides, such as a function or variable name. These errors occur at runtime -- that is, after the script has been loaded and code is executed.
Note: The xyz identifier may not always appear in the error message. For example, instead of saying "myObject cannot be indexed as an array," the error message may simply say, "cannot be indexed as an array." Fortunately, JavaScript does provide the number of the approximate line that contains the error, which can help in tracking down the source of a problem.
Only objects can be indexed as an array, and this error typically occurs when you attempt to use a non-object as an array (the error also occurs if you attempt to use an array not supported by a given object, such as document.elements[0]). The following results in an error because window.length is a property, and not an object.
alert (window.length[0]);
However, the following does work because a number of properties are contained in the document object. The array index values access each of the available properties.
alert (document[0]);
The object you've referenced has no properties. This is a common error, and is usually the result of misusing objects. This error will crop up, for example, with the following:
document.history.go(1);
The error occurs because history is a property of a window, not a document. The correct syntax is:
window.history.go(1)
This error occurs when your JavaScript code references a variable or object that does not exist. For example, you get the error with the following. (Note that the assigned variable is Test, whereas the variable used with the alert method is Text.)
var Test="This is a test;
alert (Text);
Another common mistake is to use the wrong capitalization when referring to variables and objects. This code results in an error, even though you have spelled the variable name correctly:
var Test="This is a test;
alert (test);
Debugging JavaScript programs may not be state-of-the-art (yet, anyway). Nevertheless, with a bit of sleuthing, and a handful of simple tools and techniques, you can debug most any JavaScript coding problem you may encounter. And as you might expect, the process gets easier as you become more experienced at programming in JavaScript.
Read more about Tools & Methods in JavaWorld's Tools & Methods section.