Temporal.PlainDate.prototype.valueOf()

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The valueOf() method of implicitly converted to primitives when used in arithmetic or comparison operations.

Syntax

js
valueOf()

Parameters

None.

Return value

None.

Exceptions

TypeError

Always thrown.

Description

Because both Temporal.PlainDate.compare() static method to compare them.

Examples

Arithmetic and comparison operations on Temporal.PlainDate

All arithmetic and comparison operations on Temporal.PlainDate instances should use the dedicated methods or convert them to primitives explicitly.

js
const date1 = Temporal.PlainDate.from("2022-01-01");
const date2 = Temporal.PlainDate.from("2022-07-01");
date1 > date2; / TypeError: can't convert PlainDate to primitive type
Temporal.PlainDate.compare(date1, date2); / -1

date2 - date1; / TypeError: can't convert PlainDate to primitive type
date2.since(date1).toString(); / "P181D"

Specifications

Specification
Temporal
# sec-temporal.plaindate.prototype.valueof

Browser compatibility

See also

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant