Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to reproduce TypeError: 'undefined' is not an object

Tags:

Google Analytics shows that ~12% of our total users are affected by a Javascript bug of:

TypeError: 'undefined' is not an object

90% of the browsers are Safari 7534.48.3, 10% are Mozilla compatible agent. 75% of the errors come from iPhones, 23% from iPads. 1% from Macintosh, the other 2% is from iPod etc. None of the devices run Linux or Windows.

I have tried enabling debug mode in safari on both an iPhone and iPad but not able to reproduce the bug.

Here is a link to a page Google Analytics claims is showing the error. If anyone can consistently reproduce the error here I will be super happy because just a line number would be enough to get me started debugging.

Can anyone think of any other ways I can try to debug this? Thanks all

For the curious among us I'm using this code to send errors to GA -- Warning: Possible self promotion.

Update: TypeError: 'undefined' is not an object (evaluating 'safari.self.tab.canLoad')

Managed to get that out of it once when clicking around, mostly on an iphone whilst clicking "Change country.."

Update: Solved this by making sure the element was available in the dom. Turns out the ajax call on success was trying to write to an element that wasn't available.

I have kept a solid record of Unable to reproduce TypeError: 'undefined' is not an object here

like image 718
John McLear Avatar asked Apr 09 '12 18:04

John McLear


People also ask

What is the reason for getting error TypeError undefined is not an object?

The Cause. Simply, you're treating a variable like it is an object when it is not. 'undefined' means that your variable hasn't yet been defined (in this case, our object has either not been instantiated or it has been but not assigned to the variable that you are using.

What is the reason for getting error TypeError undefined is not an object evaluating this Setstate?

The “TypeError: 'undefined' is not an object” error occurs when a property is accessed or a method is called on an undefined object.


1 Answers

Undefined

The undefined type has only one value: undefined. It’s the default value that all variables have after a declaration if no value is assigned to them. You can also assign the value undefined to any variable, but in general, this should be avoided, because if we need to mark a variable as not holding any meaningful value, we should use null.

Let declaredVar; console.log(typeof declaredVar); // -> undefined  declaredVar = 5; console.log(typeof declaredVar); // -> number  declaredVar = undefined; console.log(typeof declaredVar); // -> undefined  The undefined value can also be returned by the typeof operator when a non-existent variable is used as an argument.  Console.log(typeof notDeclaredVar); // -> undefined console.log(notDeclaredVar); // -> Uncaught ReferenceError: notDeclared is not defined 
like image 145
Dandev Avatar answered Oct 25 '22 15:10

Dandev