Typeerror: Cannot Read Property 'readable' of Null

JavaScript Errors and How to Fix Them

JavaScript tin be a nightmare to debug: Some errors information technology gives can be very difficult to understand at first, and the line numbers given aren't e'er helpful either. Wouldn't it exist useful to have a listing where you lot could expect to find out what they mean and how to fix them? Here yous get!

Beneath is a list of the strange errors in JavaScript. Dissimilar browsers can give yous unlike messages for the same error, so at that place are several different examples where applicable.

How to read errors?

Earlier the listing, let's quickly look at the structure of an error message. Agreement the structure helps empathise the errors, and you'll have less trouble if you run into any errors not listed here.

A typical error from Chrome looks like this:

Uncaught TypeError: undefined is non a function

The structure of the mistake is as follows:

  1. Uncaught TypeError: This part of the message is usually not very useful. Uncaught means the fault was not defenseless in a catch statement, and TypeError is the mistake's name.
  2. undefined is not a function: This is the bulletin part. With error messages, you accept to read them very literally. For example in this example it literally means that the code attempted to use undefined like it was a function.

Other webkit-based browsers, like Safari, requite errors in a like format to Chrome. Errors from Firefox are similar, but practice not always include the get-go part, and recent versions of Cyberspace Explorer besides give simpler errors than Chrome – but in this case, simpler does not always mean ameliorate.

At present onto the actual errors.

Uncaught TypeError: undefined is not a function

Related errors: number is not a function, object is non a part, string is not a function, Unhandled Error: 'foo' is non a function, Function Expected

Occurs when attempting to call a value like a function, where the value is not a part. For example:

var foo = undefined; foo();

This fault typically occurs if you lot are trying to call a function in an object, but you typed the name wrong.

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

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

The other variations such as "number is non a function" occur when attempting to call a number like it was a role.

How to fix this error: Ensure the function name is right. With this error, the line number will commonly point at the right 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 near common example of this error is with if-clauses:

if(doSomething() = 'somevalue')

In this example, the developer accidentally used a single equals instead of ii. The bulletin "left-hand side in assignment" is referring to the function on the left side of the equals sign, so like you tin see in the above case, the left-paw side contains something yous tin can't assign to, leading to the mistake.

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

Uncaught TypeError: Converting round structure to JSON

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

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

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

Because both a and b in the higher up instance have a reference to each other, the resulting object cannot be converted into JSON.

How to fix this mistake: Remove round references similar in the case from whatsoever objects you lot want to convert into JSON.

Unexpected token ;

Related errors: Expected ), missing ) later 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 error doesn't signal to the correct identify, making information technology difficult to set up.

  • An error with [ ] { } ( ) is ordinarily caused past a mismatching pair. Bank check that all your parentheses and brackets accept a matching pair. In this instance, line number volition frequently indicate to something else than the trouble grapheme
  • Unexpected / is related to regular expressions. The line number for this will normally be right.
  • Unexpected ; is unremarkably acquired by having a ; inside an object or array literal, or within the argument list of a office telephone call. The line number volition ordinarily be correct for this instance also

Uncaught SyntaxError: Unexpected token ILLEGAL

Related errors: Unterminated Cord Literal, Invalid Line Terminator

A string literal is missing the closing quote.

How to fix this mistake: Ensure all strings take the correct endmost quote.

Uncaught TypeError: Cannot read property 'foo' of nada, Uncaught TypeError: Cannot read holding 'foo' of undefined

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

Attempting to read goose egg or undefined as if it was an object. For case:

var someVal = null; panel.log(someVal.foo);

How to fix this mistake: Usually caused by typos. Check that the variables used virtually the line number pointed by the error are correctly named.

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

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

Attempting to write goose egg or undefined as if information technology was an object. For example:

var someVal = null; someVal.foo = one;

How to fix this mistake: This too is usually caused by typos. Check the variable names near the line the error points to.

Uncaught RangeError: Maximum phone call stack size exceeded

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

Ordinarily acquired by a bug in plan logic, causing space recursive function calls.

How to fix this error: Check recursive functions for bugs that could cause them to go along recursing forever.

Uncaught URIError: URI malformed

Related errors: URIError: malformed URI sequence

Acquired by an invalid decodeURIComponent call.

How to fix this error: Check that the decodeURIComponent telephone call at the error'due south line number gets right input.

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

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

This error is always caused by the usage of XMLHttpRequest.

How to prepare this error: Ensure the request URL is correct and it respects the same-origin policy. A good way to find the offending code is to look at the URL in the error bulletin and observe it from your code.

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

Related errors: InvalidStateError, DOMException lawmaking 11

Means the code called a function that you should not telephone call at the current state. Occurs unremarkably with XMLHttpRequest, when attempting to call functions on it before it's prepare.

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

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

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

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 beginning to make more sense. Modern browsers too help, every bit they no longer give the completely useless errors they used to.

What's the well-nigh confusing error yous've seen? Share the frustration in the comments!

Want to acquire more than most these errors and how to foreclose them? Detect Problems in JavaScript Automatically with ESLint.

Website performance monitoring

Website performance monitoring

Jani Hartikainen

Most Jani Hartikainen

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

jordanfisittests.blogspot.com

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

0 Response to "Typeerror: Cannot Read Property 'readable' of Null"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel