I checked out the link: and I got it...

Not just comparing "string to string", but for any other
type operators and their values.



-----Original Message-----
From: Dave Watts [mailto:dwa...@figleaf.com] 
Sent: Wednesday, October 05, 2011 4:44 PM
To: cf-talk
Subject: Re: Shouldn't these statements work?


> My understanding from what I've read is that the "===" operator
> should be used only when comparing strings.  Is that not correct?

That is not correct. The identity operator is intended to compare the
identity of two object references.

https://developer.mozilla.org/en/JavaScript/Reference/Operators/Comparison_O
perators

For example:

// define a custom object constructor
function Thing(arg) {
     this.property = arg;
     return this;
}

var obj1 = new Object(...);
var obj2 = obj1; // pass obj1 to obj2 by reference
if (obj1 === obj2) ... // should evaluate to true
var obj3 = new Thing("some_arg");
var obj4 = new Thing("some_arg");
if (obj3 === obj4) ... // should evaluate to false, even though both
objects have the same type and contain the same value(s)
obj4.property = obj3.property // pass obj3.property by value
if (obj3 === obj4) ... // should still evaluate to false

Now, while this is how the identity operator is intended to work,
there are some variations in its actual implementation, such that it
will just compare object types and values in some JS engines. Take a
look here:

http://blog.agilejedi.com/2008/09/javascript-equality-versus-identity.html

In any case, there's no point to using it when comparing two string
literals.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:347976
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to