Aloso Aloso - 1 year ago 78
Javascript Question

type of Date object

I just read this article on W3Schools about type conversion in JS. There stands:


There are 3 types of objects:


  • Object

  • Date

  • Array




This confused me because to my knowledge there isn't any difference between
Date
objects and any other object (
typeof (new Date())
returns
"object"
). First I thought that it's special because it contains native code, but there are dozens of functions with native code.

Is this article wrong? Or could anybody tell my why the
Date
object is so extraordinary that it's considered a separate type of object?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download