Skip to content

Check if a variable is a date in JavaScript?

We can use these code snippets to determine if a variable is a date in JavaScript.

instanceOf

let d = new Date();
console.log(d instanceof Date)
//true
Advertisements

Object.prototype.toString.call()

let d = new Date();
console.log(Object.prototype.toString.call(d) === "[object Date]")
//true
See also  How to convert JavaScript Array to comma separated string?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.