type of Date object
You might check an object for being an instance of a specific type also by verifying whether it has a method that is specific to the object type in question:
if (myobject.hasOwnProperty("getUTCMilliseconds")) {
// myobject is a Date...
The same technique may help you identifying arrays in Javascript:
checking
typeof(myobject)
yields "object"
, not "array"
if myobject
is really an array, so I use
if (myobject.hasOwnProperty("slice")) {
// we are dealing with an array here ...
Lemme tell you a basic thing. The articles in W3Schools are definitely outdated so you must not rely on it. Yes, when you give this in console:
typeof (new Date())
The above code returns object
because the JavaScript has only a few primitive types:
You can check if it is a date
object or not using:
(new Date()) instanceof Date
The above code will return true
. This is the right way of checking if the particular variable is an instance of a particular type.