Recently in Chrome I made this observation while debugging an angularjs application.
console.log(scope.myObj.someProperty)
> undefined
and yet when I type in
scope.myObj
I get the collapsible tree representation of scope.myObj
with someProperty
clearly available as a key on the object with a value like "hello world"
. It was not a member of __proto__
but clearly right there as a key of scope.myObj
.
How can this possibly be?
In other words: How can it be possible for scope.myObj.someProperty
to be undefined when passing in as an argument to console.log
and yet available for parsing when Chrome creates that collapsible tree?
EDIT: The second statement was executed immediately after the first, and the 2 commands were repeated about 3 times just to verify the output. I'm having a hard time replicating this to provide more code here, which is why the lack of context. I would rather not post the full source code of all the directives and whatnot from the angular app. The only sanity check I did was to check in with a few colleagues to verify that I wasn't completely missing something, which I wasn't.
2nd EDIT: This question has been marked as a duplicate of AngularJS - Simple $scope console.log() returns undefined. I don't think this is a duplicate because my question is not "why was my scope value undefined". My question is "why was my scope value undefined when using console.log
to print it, yet available on the scope when browsing Chrome's collapsible tree view of the scope object?`.