EN
JavaScript - test if variable is date type
3
points
In this short article, we would like to show how to check if the variable is date type.
Quick solution:
// ONLINE-RUNNER:browser;
function isDate(value) {
return value instanceof Date;
}
// Usage example:
var value1 = '2020-07-02';
var value2 = new Date();
var value3 = Date.now();
console.log(isDate(value1)); // false
console.log(isDate(value2)); // true
console.log(isDate(value3)); // false
Note: read this article to know how to check variable type.