Aloso Aloso - 1 year ago 89
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
objects and any other object (
typeof (new Date())
). 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
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