DEV Community

Discussion on: How to Check if Object is Empty in JavaScript

Collapse
 
prahladyeri profile image
Prahlad Yeri

A typical programming practice is to set your object variable as undefined at first, so that comparison becomes much simpler for that later in code. All you have to do is:

var foo = undefined;
....
if (foo===undefined) doSomething();
....

The same holds true when you return a function value, return either a boolean or undefined as a falsy value to avoid trouble latter.