Sometimes, we want to check if a variable is a Date in JavaScript.
In this article, we’ll look at how to check if a variable is a Date in JavaScript.
How to check if a variable is a Date in JavaScript?
To check if a variable is a Date in JavaScript, we can use the instanceof
operator.
For instance, we write
myVar instanceof Date;
to check if myVar
is a Date
instance with the instanceof
operator to check if it’s a date.
Conclusion
To check if a variable is a Date in JavaScript, we can use the instanceof
operator.