Can I check if an object exists?

R

Richard Cornford

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. ...
<snip>

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.

They are both equally valid in what they attempt to do.
Yours is no more correct than mine.
<snip>

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.
 
Z

ZER0

[T]he point is: typeof is not slower than "boolean check":
Yes, it is.

Not it isn't.
The benchmark on about 20.000 cycles report the same speed IE/Gecko.
Sometimes the boolean check is a bit faster, sometime the typeof is a bit
faster.
[MLW:]
if (ref!=null)
this is correct.
They are both equally valid in what they attempt to do. Yours is no
more correct than mine.

I'm not agree. The result is the same, but there aren't the same
comparison.
It is better in your opinion.

Not exactly. Remember the question about coding style and team works.
It's the same reason 'cause it's a good idea use a "notation" for variables
name.
It is not in mine. I do not equate
verbosity with clarity, nor do I feel that it is more correct.
I don't think that either approach can objectively be declared the "best".

It's your opinion.
[MLW:]
Yes, but is not the perfect method, and the code is more ambiguos than
typeof checking.
You are disagreeing purely on a stylistic basis.

Not only, but also a js engine viewpoint.
We will just have to agree to disagree. There is nothing factual left
to debate, so let's just drop the conversation, shall we?

Yes, I'm agree. I'm good "orator" but in my mother language. My english is
not so good for explain perfectly my view point and my reasons.

--
ZER0

~ The Tangent Universe collapsed 5967 days, 2 hours, 41 minutes and 17 seconds ago.

on air ~ "See Saw - Edge"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top