Skip to content Skip to sidebar Skip to footer

Typeerror: Cannot Read Property 'show Expanded Abbreviation' of Undefined

JavaScript Errors and How to Set up Them

JavaScript can be a nightmare to debug: Some errors it gives can be very difficult to understand at first, and the line numbers given aren't always helpful either. Wouldn't it exist useful to have a list where you could look to find out what they mean and how to fix them? Here you go!

Below is a listing of the strange errors in JavaScript. Different browsers can give y'all different messages for the aforementioned fault, and then at that place are several different examples where applicable.

How to read errors?

Before the list, let's rapidly look at the structure of an fault message. Agreement the structure helps sympathise the errors, and you lot'll have less trouble if you lot see whatsoever errors not listed here.

A typical mistake from Chrome looks like this:

Uncaught TypeError: undefined is not a function

The structure of the error is every bit follows:

  1. Uncaught TypeError: This part of the message is usually not very useful. Uncaught means the error was not caught in a catch argument, and TypeError is the mistake's name.
  2. undefined is not a role: This is the bulletin function. With error messages, y'all take to read them very literally. For case in this case it literally means that the code attempted to apply undefined like it was a function.

Other webkit-based browsers, similar Safari, give errors in a like format to Chrome. Errors from Firefox are similar, only do not e'er include the first function, and recent versions of Internet Explorer likewise give simpler errors than Chrome – just in this case, simpler does not always mean better.

At present onto the actual errors.

Uncaught TypeError: undefined is non a role

Related errors: number is not a part, object is not a function, string is not a part, Unhandled Mistake: 'foo' is not a function, Part Expected

Occurs when attempting to phone call a value like a function, where the value is not a role. For case:

var foo = undefined; foo();

This error typically occurs if you are trying to call a role in an object, but yous typed the name wrong.

var x = certificate.getElementByID('foo');

Since object properties that don't exist are undefined by default, the above would result in this error.

The other variations such every bit "number is not a function" occur when attempting to call a number similar information technology was a part.

How to fix this error: Ensure the function proper noun is correct. With this error, the line number will usually point at the correct location.

Uncaught ReferenceError: Invalid left-hand side in assignment

Related errors: Uncaught exception: ReferenceError: Cannot assign to 'functionCall()', Uncaught exception: ReferenceError: Cannot assign to 'this'

Caused by attempting to assign a value to something that cannot be assigned to.

The most common example of this error is with if-clauses:

if(doSomething() = 'somevalue')

In this example, the developer accidentally used a single equals instead of 2. The bulletin "left-hand side in assignment" is referring to the part on the left side of the equals sign, then similar you tin can see in the higher up example, the left-hand side contains something you lot tin can't assign to, leading to the error.

How to fix this error: Make sure you're not attempting to assign values to function results or to the this keyword.

Uncaught TypeError: Converting round construction to JSON

Related errors: Uncaught exception: TypeError: JSON.stringify: Non an acyclic Object, TypeError: cyclic object value, Circular reference in value argument not supported

Always caused by a round reference in an object, which is then passed into JSON.stringify.

var a = { }; var b = { a: a }; a.b = b; JSON.stringify(a);

Considering both a and b in the above example have a reference to each other, the resulting object cannot be converted into JSON.

How to set up this error: Remove circular references similar in the instance from any objects you lot want to convert into JSON.

Unexpected token ;

Related errors: Expected ), missing ) afterward argument list

The JavaScript interpreter expected something, but it wasn't there. Typically caused by mismatched parentheses or brackets.

The token in this error can vary – information technology might say "Unexpected token ]" or "Expected {" etc.

How to fix this fault: Sometimes the line number with this mistake doesn't signal to the correct identify, making information technology difficult to fix.

  • An error with [ ] { } ( ) is usually caused by a mismatching pair. Check that all your parentheses and brackets have a matching pair. In this example, line number volition often point to something else than the problem character
  • Unexpected / is related to regular expressions. The line number for this will usually be correct.
  • Unexpected ; is unremarkably caused by having a ; inside an object or array literal, or within the argument list of a function call. The line number will commonly be correct for this case as well

Uncaught SyntaxError: Unexpected token ILLEGAL

Related errors: Unterminated String Literal, Invalid Line Terminator

A cord literal is missing the endmost quote.

How to fix this error: Ensure all strings have the correct closing quote.

Uncaught TypeError: Cannot read holding 'foo' of null, Uncaught TypeError: Cannot read holding 'foo' of undefined

Related errors: TypeError: someVal is null, Unable to become property 'foo' of undefined or goose egg reference

Attempting to read null or undefined as if it was an object. For instance:

var someVal = nothing; console.log(someVal.foo);

How to ready this fault: Usually caused by typos. Check that the variables used about the line number pointed by the error are correctly named.

Uncaught TypeError: Cannot set property 'foo' of null, Uncaught TypeError: Cannot fix property 'foo' of undefined

Related errors: TypeError: someVal is undefined, Unable to fix property 'foo' of undefined or null reference

Attempting to write zip or undefined equally if it was an object. For instance:

var someVal = zippo; someVal.foo = 1;

How to fix this error: This likewise is commonly caused past typos. Check the variable names near the line the fault points to.

Uncaught RangeError: Maximum telephone call stack size exceeded

Related errors: Uncaught exception: RangeError: Maximum recursion depth exceeded, too much recursion, Stack overflow

Usually caused by a bug in program logic, causing infinite recursive office calls.

How to gear up this error: Cheque recursive functions for bugs that could cause them to keep recursing forever.

Uncaught URIError: URI malformed

Related errors: URIError: malformed URI sequence

Caused past an invalid decodeURIComponent call.

How to set this error: Cheque that the decodeURIComponent telephone call at the fault'southward line number gets right input.

XMLHttpRequest cannot load http://some/url/. No 'Access-Command-Allow-Origin' header is present on the requested resource

Related errors: Cantankerous-Origin Asking Blocked: The Same Origin Policy disallows reading the remote resource at http://some/url/

This fault is always caused by the usage of XMLHttpRequest.

How to fix this fault: Ensure the request URL is correct and information technology respects the same-origin policy. A good way to find the offending code is to expect at the URL in the error message and find it from your code.

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

Related errors: InvalidStateError, DOMException code xi

Means the code chosen a part that you should not call at the current state. Occurs usually with XMLHttpRequest, when attempting to phone call functions on it before it's ready.

var xhr = new XMLHttpRequest(); xhr.setRequestHeader('Some-Header', 'val');

In this case, you would go the error because the setRequestHeader function can simply be called after calling xhr.open.

How to fix this fault: Look at the code on the line pointed by the error and make sure it runs at the correct fourth dimension, or add together any necessary calls before it (such as xhr.open up)

Determination

JavaScript has some of the most unhelpful errors I've seen, with the exception of the notorious Expected T_PAAMAYIM_NEKUDOTAYIM in PHP. With more familiarity the errors start to brand more sense. Mod browsers also help, as they no longer requite the completely useless errors they used to.

What's the most confusing error you've seen? Share the frustration in the comments!

Desire to learn more than near these errors and how to prevent them? Notice Problems in JavaScript Automatically with ESLint.

Website performance monitoring

Website performance monitoring

Jani Hartikainen

About Jani Hartikainen

Jani Hartikainen has spent over 10 years building web applications. His clients include companies like Nokia and hot super secret startups. When not programming or playing games, Jani writes about JavaScript and high quality code on his site.

meyersliare1952.blogspot.com

Source: https://davidwalsh.name/fix-javascript-errors

Enregistrer un commentaire for "Typeerror: Cannot Read Property 'show Expanded Abbreviation' of Undefined"