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?
false- see stackoverflow.com/questions/7858787/… Can you post the complete code causing your issue and tell us what 'blow up' actually means (what error do you encounter)?typeofwill not return the desired results in some cases. For instance, ifvar1is an array,typeof var1will still beobject. See here for more details.