What is the difference?


#1

What is the difference between 'new Date()' and 'Date()' when I use them as variable?
For eg-
var x = new Date()
and
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.


#2

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
"string"
typeof y
"object"

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.

Update
Hope this link will help you:


#3

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