Array.prototype.indexOf use of SameValue()

Allen Wirfs-Brock Allen.Wirfs-Brock at
Tue Apr 28 11:48:17 PDT 2009

The first step of SameValue is 
1.	If Type(x) is different from Type(y), return false.

undefined, null, and number are 3 distinct types so SameValue(null,1) -> false and SameValue(undefined,1) -> false

>-----Original Message-----
>From: es-discuss-bounces at [mailto:es-discuss-
>bounces at] On Behalf Of John-David Dalton
>Sent: Tuesday, April 28, 2009 11:35 AM
>To: es-discuss at
>Subject: Array.prototype.indexOf use of SameValue()
>In the ECMA 5 RC spec I noticed that Array.prototype.indexOf
>(and lastIndexOf) make use of the SameValue operation.
>The spec states that (9.12)  SameValue will return true If Type(x) is
>Undefined or Null.
>Would this not cause an issue with 9c of the Array.prototype.indexOf
>"c. If SameValue(searchElement,elementK) is true,  return k.".
>[1,2,null].indexOf(null) -> SameValue(null, 1) -> true, return 0.
>var undef;
>[1,2,undef].indexOf(undef) -> SameValue(undefined, 1) -> true, return 0.
>- JDD
>es-discuss mailing list
>es-discuss at

More information about the es-discuss mailing list