is date object javascript code example

Example 1: javascript date is an object

The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ) as shown below. ... Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.

Example 2: js is date

typeof date.getMonth === 'function'
// you can use the instanceof operator, i.e. But it will return true for invalid dates too, e.g. new Date('random_string') is also instance of Date
date instanceof Date
// This will fail if objects are passed across frame boundaries.
// A work-around for this is to check the object's class via
Object.prototype.toString.call(date) === '[object Date]'