1

How come new Date() gives me different output format in VS Code from other places (at least in Chrome console). I also noticed that in VS code, Date() (without 'new' operator) gives me same result as in Chrome console. What's the dealio?

In VS code:

console.log(new Date());
// 2021-01-26T21:11:59.074Z

In Chrome console:

console.log(new Date());
//Tue Jan 26 2021 16:12:45 GMT-0500 (Eastern Standard Time)

However... In VS code:

console.log(Date());
//Tue Jan 26 2021 16:16:42 GMT-0500 (Eastern Standard Time)
PurpleMongrel
  • 112
  • 1
  • 9
  • `Date()` returns a string, `new Date()` returns a Date object. As to why VS Code stringifies them differently? ¯\\_(ツ)\_/¯ – evolutionxbox Jan 26 '21 at 21:22
  • Does this answer your question? [Date vs new Date in JavaScript](https://stackoverflow.com/questions/9584719/date-vs-new-date-in-javascript) – Get Off My Lawn Jan 26 '21 at 21:26
  • 4
    Because a debug console is a proprietary tool and every vendor is free to display objects however they like (and think the user benefits most). Some consoles are text-only (and require serialisation), others are more advanced and allow interactive inspection. – Bergi Jan 26 '21 at 21:26
  • Take a look here: https://jsfiddle.net/5jcfehtk/ –  Jan 26 '21 at 21:27
  • @Bergi Ah I see... Thank you – PurpleMongrel Jan 28 '21 at 21:04

0 Answers0