javascript - Can this type checks with "object" be improved? -


if (typeof !== "object" && typeof b !== "object") {     return == b; } ... // check pairwise equality of object & b using `for in` 

is same

if (typeof !== "object") {     return == b; } 

is there b typeof b === "object" change semantics?

are there horrible edge cases should aware of? comparisons between object , native type have non-intuitive boolean equality or disequality? including bugs in browser (i mean ie6!)

the second check not quite same first, no, because javascript weakly typed @ least consider ".tostring() effect", others. example these fail first check, pass in second:

var = "[object object]"; var b = {}; 

or, bit simpler (showing case may want consider...but passes both checks):

var = 0; var b = "0"; 

one fix value and type check === which strict comparison operator, type checking well...but i'm not entirely sure that's you're after, since current check explicitly "not object".


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -