1

I have two javascript dates, dt and Frefdate. In the firebug, both value are Date {Fri Apr 08 2005 00:00:00 GMT+1000 (AUS Eastern Summer Time)}.

But dt == Frefdate is false. I have to use dt.valueOf() == Frefdate.valueOf() to compare these two dates. Why?

in w3schools web site, the dates comparison can be date1 > date2.(see http://www.w3schools.com/js/js_obj_date.asp).

Thank you.

peter
  • 1,009
  • 3
  • 15
  • 23

2 Answers2

1

When you compare two different date objects, you aren't comparing their value, you're comparing that they are in fact the same object.

Even if the two date objects are set to the same date and time, they are two separate instances. Think of it like comparing references to a structure in memory. The memory location for each is going to be different.

Brad
  • 159,648
  • 54
  • 349
  • 530
0

The two dates are two different objects, so they are not "object-equal". JavaScript lets you compare strings and numbers using ==, but all other types are compared as objects.

ltalhouarne
  • 4,586
  • 2
  • 22
  • 31