Is there any way to make an object return false in javascript?
var obj = new Object(); console.log(!!obj) // prints \"true\" even if it\'s empty
A null "object" (really value) will return false.
var obj = null; console.log(!!obj);
If you wanted to check if it has no properties, you might try:
var obj = new Object(); var empty = true; for (var p in obj) { if (obj.hasOwnProperty(p)) { empty = false; break; } } console.log(empty);