CyrefJS
CCyrefJS
فا
Back to documentation
Type/Since 1.38.0

isDate

Checks whether a value is an instance of Date and provides a TypeScript type guard for Date narrowing.

isDate(value):value is Date

Implementation

The function uses the JavaScript instanceof operator to check whether the value is an instance of Date.

Type guard

The return type `value is Date` makes the function a TypeScript type guard. When it returns true, TypeScript can treat the value as a Date within the narrowed scope.

Invalid Date objects

This function checks the object's type, not whether the Date contains a valid timestamp. Therefore, an invalid Date object still returns true.

Parameters

valueunknownrequired

The value to check.

Returns

value is Date

Returns true when the value is an instance of Date; otherwise returns false. When true, TypeScript narrows the value to Date.

Examples

01

Basic usage

Check whether a value is a Date instance.

TypeScript
isDate(new Date());
// true

isDate("2026-09-24");
// false
02

Type narrowing

The type guard narrows an unknown value to Date inside the conditional block.

TypeScript
const value: unknown = new Date();

if (isDate(value)) {
  value.getTime();
  // value is narrowed to Date
}
03

Invalid Date

An invalid Date object is still an instance of Date, so it returns true.

TypeScript
const value = new Date("invalid");

isDate(value);
// true
04

Other values

Strings, numbers, null, undefined, and plain objects are not Date instances.

TypeScript
isDate("2026-09-24");
// false

isDate(0);
// false

isDate(null);
// false

isDate({});
// false
Built with@cyref/js·Official documentation