The difference between "new date (). ValueOf ()" and Date (). ValueOf () "

Why do the two expressions below return different results?

Date().valueOf()
"Fri Feb 07 2014 16:03:34 GMT-0500 (Eastern Standard Time)"

new Date().valueOf()
1391807020802

Date().toString()
"Fri Feb 07 2014 16:09:21 GMT-0500 (Eastern Standard Time)"

new Date().toString()
"Fri Feb 07 2014 16:09:26 GMT-0500 (Eastern Standard Time)"
+3
source share
1 answer

Date() returns a timestamp formatted as a string.

new Date()returns an instance Date.

Constructor instances Datehave values ​​that are converted to numbers, so it new Date().valueOf()returns a number. Strings are just strings, so when you call Date().valueOf(), you get the same string result.

+6
source

All Articles