I check for a property on an object but it returns undefined even though it is there. I assume I am testing in the wrong way?
I run this
console.log(self.modules[moduleId]);
and it outputs this:
Object
composed: Array[2]
prototypes: Array[2]
slideshow: Slideshow
cardFront: false
currentSlide: 2
(So "slideshow" is an object, an instance of my class "Slideshow".)
I step in one step further to do this:
console.log(self.modules[moduleId].slideshow);
And it returns undefined.
My if-statement looks like this, although above is probably enough to get my issue.
if ( typeof( self.modules[moduleId].slideshow == 'undefined' ) ) {
self.modules[moduleId]really is the object structure you quote, then obviouslyself.modules[moduleId].slideshowisn'tundefined. So something's got lost in the formation of the question.if(typeof self.modules[moduleId].slideshow == 'undefined')would be correct (orif((typeof self.modules[moduleId].slideshow) == 'undefined'), but those are unnecessary). ANd, another thing: keep in midn that this only checks.slideshow. Ifmodules[moduleId]doesn't exist in the first palce, you still get an error - so check that one first.()create "ambiguity," it's that they make the expression wrong.==will always return a boolean.typeofwill always be"boolean"with the()as in the OP's question, because the()maketypeofapply to the expression rather than toself.modules[moduleId].