I have code like this:
function doAThing(var1) {
return typeof var1 === "object" && Object.keys(var1).length > 11;
}
I'm having a problem where when var1
is NOT an object the function tries to return the value of the last statement: Object.keys(var1).length > 11)
Obviously, if obj1
is not an object i don't want to try and get it's keys or it will blow up with Cannot convert undefined or null to object
.
How can i get this function to return a boolean and NOT try to check var1
's keys if it's not an object?