Closed michaelficarra closed 10 years ago
I believe to (typeof a == "undefined" || a == null)
and (a.b == null)
, notice the braces
@dvv: Depending on the situation, possibly. But the compiler will handle that for us.
Yes, I was a bit puzzled that these two behave differently:
foo unless a?
foo if not a?
Namely:
if (typeof a == "undefined" || a === null) {
foo;
}
if (!(typeof a != "undefined" && a !== null)) {
foo;
}
@jrus: They don't behave differently, but they do (unfortunately) compile differently.
Yeah, I meant the compiler behaves differently, not that the output behaves differently. Silly ambiguous English. :)
Seems to work that way.
A minor optimization:
!a?
!(typeof a != "undefined" && a != null);
typeof a == "undefined" || a == null;
!a.b?
!(a.b != null);
a.b == null;