Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

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

0
hankknight
Asked:
hankknight
1 Solution
 
leakim971PluritechnicianCommented:
"undefined" not undefined
test page : http://jsfiddle.net/awgLW/
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now