Frontend Scrapbook

Notes that make a difference

Date() vs new Date()

By admin

on Fri May 08 2020

‘Date’ in Javascript, when invoked as a function returns a string representing the current time ( UTC ) ignoring ANY arguments

When Date is called as part of a new operator as a constructor invocation, it initializes new object with provided arguments

let date1 = Date(timestamp);
let date2 = new Date(timestamp);

Here, date1 represents the current time in UTC ignoring the timestamp value. date2 returns the date object representing the timestamp.