JavaScript debugging Programmers spend a lot of time diagnosing and remedying errors and omissions in their code. Debugging slows down the JavaScript execution and shows how data is modified line by line. Since JavaScript is interpreted at run time and executed inside the browser, debugging is performed with tools built in to the browser. Errors in JavaScript In JavaScript an error is detected or thrown when a program tries to perform an unexpected or forbidden action. JavaScript uses an Error object to provide information about the unexpected event. JavaScript errors can be viewed in a browser’s Developer Tools,
SyntaxError An error in the way the code is written causes a syntax error. This error occurs while the JavaScript Engine is interpreting the code at run time.
inside the Console tab. Every Error object has two properties, a “name” and a “message”. The name indicates the type of error, while the message provides further details about the error, such as the location in the JavaScript file where the error was thrown.
TypeError This error occurs when the wrong data type is used. For example, applying the string.substring method to a variable that is a number.
URIError Some alphanumeric characters are not allowed to be used in a url. A URIError is thrown when there is a problem encoding or decoding a URI because of the use of a reserved character. ReferenceError This error occurs when the code refers to a variable that either does not exist or is not in scope (see p.269) for the executing code.
RangeError When the code attempts to use a number that is outside the range of possible values, JavaScript detects a RangeError.
EvalError This error occurs when there is a problem with the eval() function. Newer versions of JavaScript do not throw this error.