So i've read a handful of SO posts and some blogs, but still can't figure out why my code isn't working.
My code:
function myFunct(d) {
if (typeof d.parent.name == "undefined") {
console.log("undefined") ;} else { console.log("defined") ;}
}
d is an object that looks something like:
Object {
children: Object,
count: 676
}
I've tried using (!d.parent.name), hasOwnProperty, ===, and as above using typeof. Any suggestions?
The error I recieve is TypeError: d.parent.name is undefined
UPDATE:
Ok thanks everyone for the input, and my apologies if the question was confusing. I was actually looking for d.parent.parent but tried to simplify the question by using d.parent. I think the problem is that d.parent is not defined so it doesn't even get to d.parent.parent. Sorry for not being more specific!
typeof Object === 'undefined'is a valid way to use typeofTypeErrorif (d.parent && typeof d.parent.name === 'undefined')