What's the difference between this:
if(!foo) {
...
}
And this:
if(typeof foo === "undefined") {
...
}
I've seen some code which attempts to treat these two statements as though they're identical, but I've run into problems when doing so. I've been doing something like this with AngularJS:
var property = {
value: $scope.foo //$scope.foo may or may not have been defined above, depending on contexts
...
};
func(property);
function func (property) {
if(!property.value) {
//This doesn't get executed, even if $scope.foo was never defined
}
}
It seems to me that (!foo)
!== (typeof foo === "undefined")
Is this correct?