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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. An object that doesn’t have any properties assigned is not considered “empty”.
The fact that a variable holds an instance of an object is enough to cause javascript to treat the variable as having the value of
truewhen an expression requires a boolean value.Edit
There are clearly some nuances to be cleared up looking at the other answers here.
nullis not an object, it is the distinct lack of an object. The question refers to an Object, that is one that has just been created.