DEV Community

Discussion on: Uncaught TypeError: Cannot read property of undefined In JavaScript

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Nice article. Somewhat better approach (which I personally use to avoid working with both, undefined and null variables) is checking for equality with null.

if (variable != null) {
  // do something
}

This will catch both, null and undefined values.

Collapse
 
_deekshagarwal_ profile image
Deeksha Agarwal

Thanks a lot for the suggestion Nikola. I'll take care of this as well :)