JavaScript: Check if sub variable defined

How can I do this without errors?

 if (typeof (x) !== undefined && typeof (x.y) !== undefined) {
  alert('x.y not defined');
 }
 else {
  alert('x.y is defined');
 }

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
"undefined" not undefined
test page : http://jsfiddle.net/awgLW/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.