Sethupathy Mathirajan
Sethupathy Mathirajan

Reputation: 114

Javascript error in IE9

Any body has any idea about this error,

TypeError: Unable to get value of the property 'pop': object is null or undefined:

Hi bru.scopelliti,

Here the code is:

someNode.innerHTML = _self.errorMessage + " : " + ioArgs.xhr.status + " : " +response.responseText;

The thing is the response object doesn't have responseText

Upvotes: 2

Views: 86

Answers (2)

Arninja
Arninja

Reputation: 745

This error occurs when the object is null or undefined when you want to acces a property.

var x = undefined;
var y = null;
alert(x.pop); // error
alert(x.pop); // error

If you want to check if the object is null you can just do:

if (response) {
  // Do stuff
}

If you want to check if the object property exists you can do:

if (response) {
   var value = response.responeText || defaultValue
}

Edit: From the comments:

There's a few ways for checking for something being defined, but if (something) or var x = y || z; is not the way to go because falsey values (0, '', etc.) would cause this to not work. If you want to see if something is defined, I would use if (typeof x === "undefined"). For checking for a property in an object, I would use if (x in obj), or possibly better depending on the scenario - if (obj.hasOwnProperty(x)). And for checking for null, I would use if (x == null)

Upvotes: 1

Sushant Sudarshan
Sushant Sudarshan

Reputation: 410

You might want to check for any extra commas that you may have inadvertently added or forgotten to remove. IE does not honour it.

var foo = {
    a: 1,
    b: 2,
    c: 3, // this last comma will give an error in IE.
}

Hope this helps.

Upvotes: 1

Related Questions