2

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

2
  • 8
    could you share the code Commented Nov 29, 2012 at 9:54
  • @AlvinWong I'd say more like 50%. The other 50% would be accessing a property/method on an object literal. Commented Nov 29, 2012 at 10:13

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, if it does so. i would get undefined or null. why it was "pop" undefined ?
@user1862748 I can't remember, but I think it would cause foo, in this example, to be undefined, and therefore accessing .pop of it would not be allowed
1

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)

9 Comments

Woooow....thank for your Express reply. Really i didn't try to access a property 'pop'. I am just trying to access response.responseText.
I don't think it would be an error...it would just be undefined. If you try to do something to it, like x.pop.call(this) or whatever, then it would complain.
@Ian: In Chrome, var x = undefined; alert(x.pop) returns TypeError: Cannot read property 'pop' of undefined, for me. Same for null. It might be browser-dependent. (Firefox also returns a TypeError)
@Cerbrus Yes, that's what we were just agreeing about. If you try to access a property or method on an undefined or null object, it's an exception. If you saw Arninja's original post, they were saying x.pop would throw an error for var x = { foo: "bar" }; which wasn't right, because the object we're accessing, x, is defined. x.pop will be resolved as undefined
@Cerbrus, Ian is right, I just changed this answer quite a few times actually
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.