What is the difference?


What is the difference between 'new Date()' and 'Date()' when I use them as variable?
For eg-
var x = new Date()
var x = Date()
document.getElementById(SOMETHING HERE).innerHTML = x;
The result is the same.
By the way I am a beginner and new to this forum.


I've tried this:

var x = Date()
"Mon Apr 03 2017 16:52:54 GMT+0300 (FLE Summer Time)"

var y = new Date()
Mon Apr 03 2017 16:53:14 GMT+0300 (FLE Summer Time)

typeof x
typeof y

So, Date() returns string value of current date, new Date returns an object. If you have object you can use methods to work with date.

Hope this link will help you:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.