I ran into a boolean test variable === Object(variable) but couldn't find anything that describes it.
Is it testing that variable is the same as Object(variable) and does Object(variable) cast this variable into object? Or does it do something else?
If it matches it will loop for (var key in variable) and uses key and variable[key] as parameters for another function. If it fails it uses just that variable as is.
It checks that
null (be careful: typeof null is "object")This is probably the simplest way to check these 3 conditions and it looks like a reasonable test to run before to loop on keys in a very polymorphic function.
Another one would have been typeof variable === "object" && variable.
From the MDN:
The Object constructor creates an object wrapper for the given value. If the value is null or undefined, it will create and return an empty object, otherwise, it will return an object of a Type that corresponds to the given value. If the value is an object already, it will return the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With