Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How to check for both undefined and NULL?

Here's my attempt to troubleshoot a problem that I have yet to completely track down...

But I'm getting closer!

  if(typeof json !=='undefined') {
				  console.log("you've got some JSON");
				  console.log(json);
				  console.log(json.chartData);
				  if (json.chartData) {
					  buildChart(json.chartData);
				  }    
			  }
			  else {
				  console.log("no json data");
			  }

Open in new window


This is what I get back:

you've got some JSON
null

So, I've got some JSON, but when I try to see it, I get NULL.

I'm thinking I need a better IF statement, but how?

How do I check for both "undefined" and NULL?

I tried this and it didn't work:  if(typeof json !=='undefined' || json !== NULL) {
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

That will do it!