Hmm looking at the ECMA script specification (262) turns out it's a little
more complicated than I'd thought.
It's a bit much to try and understand the various steps involved in
determining the result of the strict equality/inequality operators, suffice
it to say that section 11.9.6 shows that for the expression  x === y  that
as long as x and y are of the same type (typeof returns string so we're ok
there), if x is undefined then the result is true regardless of y's value.

So theoretically:

if (typeof someUndefined == 'fuzzyDuck')

should return true also. I won't try it now but see what happens!

--rob

On 7/22/07, Stephan Beal <[EMAIL PROTECTED]> wrote:


On Jul 22, 8:15 pm, "Rob Desbois" <[EMAIL PROTECTED]> wrote:
> Stephan,
> The only time that == or != should be used (IMO anyway) is when you
> explicitly *want* type conversion to take place. Otherwise, it's safest
(and
> faster) to use === or !==

The way i've always understood it (perhaps incorrectly) is that ===
and !== perform reference equality tests, such that ((new
String("foo")) !== (new String("foo"))). A quick test shows:

[EMAIL PROTECTED]:~$ SpiderApe -e "print( (new String('foo') === new
String('foo')))"
false

And yet:

[EMAIL PROTECTED]:~$ SpiderApe -e "print('foo' === 'foo')"
true

Weird.

(SpiderApe is simply an interpreter built on the SpiderMonkey engine -
http://SpiderApe.sf.net)

Given that, it's hard to predict how (typeof SomeUndefinedThing ===
"undefined") *should* behave, because we can show that String objects
and string literals are treated differently by ===, and we don't know
(philosophically speaking) which type of string typeof will return.
That said...

[EMAIL PROTECTED]:~$ SpiderApe -e "print(typeof NonExistent ===
'undefined')"
true

Hmmm. :/




--
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

Reply via email to