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
As of ES8, no, you cannot make an object evaluates to false in JavaScript.
In the specification, all boolean checks (? ! if etc.) depends on ToBoolean,
which is very, very simple:
If the type of the input is object, the result is true. No question asked. No valueOf, no special case.
There is no way to create a falsy object in JavaScript. Only non-objects can be falsy.
Sometimes you may run into object-like "stuff" that return false.
Empty string, for example, are used like an object all the time. document.all is another falsy "object".
These are not real objects, however. They cannot have custom properties, cannot be used as prototype, and does not always behave like an object e.g. typeof or strict equal.
This behaviour is most likely here to stay for backward compatibility.