Hi,

There's a difference between primitives ("mpg") and objects (new String
("mpg")). The == operator allows for a *lot* of type coercion; the ===
operator is _supposed_ to be a strict equality operator including type
and so "mpg" !== new String("mpg") because they're different types.
See section 11.9.6 of the spec[1] for details.

[1] http://www.ecma-international.org/publications/standards/Ecma-262.htm
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com

On Sep 2, 4:56 pm, enigment <enigm...@gmail.com> wrote:
> Hmmm, even outside the indexOf() question, this is a bit creepy to me.
> I hadn't previously tested, but these are all true, at least in
> Firefox 3.5 and IE8:
>         "mpg" === "mpg"
>         "mpg" !== new String("mpg")
>         new String("mpg") !== new String("mpg")
>         new String("mpg") != new String("mpg")
>
>         new Number(1) == 1
>         new Number(1) !== 1
>         new Number(1) != new Number(1)
>
>         [] != []
>         new Array() != new Array()
>         new Array() != []
>
>         new Object() != {}
>
> Is it an identity test -- is it the same actual object? -- maybe
> coupled with the way various types of data are stored internally? It
> looks like once the string "mpg" has been created, another literal
> "msg" is the same, but a new String object containing the same literal
> is not. The analogous tests with Number, Array, and Object values
> indicate somewhat different behavior, but since it's consistent across
> IE and Firefox, it seems inherent in the language.
>
> Can anyone explain, not *how* this actually works, but the logic
> behind it?
>
> Thanks,
> e
>
> On Sep 2, 4:28 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
>
>
>
> > You're probably running into equality vs. identity (loose equality vs.
> > strict equality).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to