R
Richard Cornford
<snip>Michael said:ZER0 wrote:
[snip]
[T]he point is: typeof is not slower than "boolean check":
Yes, it is. It might not be by much, but it /is/ slower. ...
My own timings suggest that - typeof - testing is slower than
type-converting tests by between 80 and 500%, depending on the browser
(with the average being at the upper end of that range). That is half an
order of magnitude, a big enough difference for it to be worth a script
authors while to be aware of the difference.
<snip>They are both equally valid in what they attempt to do.
Yours is no more correct than mine.
Indeed, not (type-converting) equal to null is a very particular test
and distinct from both type converting and - typeof - testing. null is
not equal to anything but itself and undefined, not zero, false or the
empty string.
As with all tests the first question is; will the test accurate
discriminate between the possibilities and tell you what you need to
know. After satisfying that other factors, such as the cost and/or
effort involved, might be used to discriminate between available tests.
Richard.