This feature is not Baseline because it does not work in some of the most widely-used browsers.
The equals() method of Temporal.PlainYearMonth instances returns true if this year-month is equivalent in value to another year-month (in a form convertible by Temporal.PlainYearMonth.from()), and false otherwise. They are compared both by their underlying ISO date values and their calendars, so two year-months from different calendars may be considered equal by Temporal.PlainYearMonth.compare() but not by equals().
Note: PlainYearMonth objects keep track of a reference ISO day, which is also used in the comparison. This day is automatically set when using the Temporal.PlainYearMonth.from() method, but can be set manually using the Temporal.PlainYearMonth() constructor, causing two equivalent year-months to be considered different if they have different reference days. For this reason, you should avoid using the constructor directly and prefer the from() method.
equals(other)
otherA string, an object, or a Temporal.PlainYearMonth instance representing the other year-month to compare. It is converted to a Temporal.PlainYearMonth object using the same algorithm as Temporal.PlainYearMonth.from().
true if this year-month is equal to other both in their date value and their calendar, false otherwise.
const ym1 = Temporal.PlainYearMonth.from("2021-08");
const ym2 = Temporal.PlainYearMonth.from({ year: 2021, month: 8 });
console.log(ym1.equals(ym2)); // true
const ym3 = Temporal.PlainYearMonth.from("2021-08-01[u-ca=japanese]");
console.log(ym1.equals(ym3)); // false
const ym4 = Temporal.PlainYearMonth.from("2021-09");
console.log(ym1.equals(ym4)); // false
| Specification |
|---|
| Temporal> # sec-temporal.plainyearmonth.prototype.equals> |
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
equals |
144 | 144 | 139 | No | No | 144 | 139 | No | No | No | 144 | No | ? | 1.40 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainYearMonth/equals