Question: Output of `console.log({a:new Date()})` is `{ a: 2019-05-19T11:30:57.514Z }`

Value of `JSON.stringify({a:new Date()})` is `{"a":"2019-05-19T11:33:12.591Z"}`

After overriding this: `Date.prototype.toJSON = function(){ return this.toLocaleString(); }`

Value of `JSON.stringify({a:new Date()})` is `{"a":"5/19/2019, 5:09:31 PM"}`

But output of `console.log({a:new Date()})` is still `{ a: 2019-05-19T11:41:31.256Z }`

Tried overriding other `Date.prototype` methods like `toISOString()`, `toSource`, `toString`, `toUTCString`, `valueOf` and many others. But none helped.

Couldn't understand the native source code of v8 js engine. 

Any way to override the behavior to get the desired result?

Answer: 
It depends on the console implementation, which isn't in V8 but rather in the host (Chrome, Chromium, Node.js, ...).

Node.js used to look for a member called `inspect` (back in v4 at least) and use that if it was present, but that turned out to be a compatibility problem and it doesn't do that anymore.

I don't think there's any way to override the console's rendering of built-in objects anymore, particularly not across host environments.
The console uses `toString` to convert dates (and other objects) to string for printing. So you can override `Date.prototype.toString` to change what gets printed. Demo (copy-pasted from a Chrome console session):

```
> var d = new Date()
> console.log(d)
< Sun May 19 2019 14:29:02 GMT+0200 (Central European Summer Time)
> Date.prototype.toString = Date.prototype.toLocaleString
< ƒ toLocaleString() { [native code] }
> console.log(d)
< 5/19/2019, 2:29:02 PM
> console.log({a:new Date()})
< {a: 5/19/2019, 2:31:21 PM}

```

A separate issue is that `JSON.stringify({a: 1})` gives `{"a":1}`, whereas `console.log({a: 1})` prints `{a: 1}` (without quotes around `a`). That's unrelated to dates, and is due to the fact that JSON is a very limited subset of JavaScript (`{a: 1}` is valid JavaScript but not valid JSON). Also, `console.log` is intended for human consumption, there is no requirement that the output can be parsed back to the original object(s) -- just consider what `console.log(new Array(100))` does :-)

---

Edit: The above is true for Chrome. Since the `console` object is not covered by the ECMAScript spec, every embedder can provide whatever they think is useful there. Node.js [uses](https://nodejs.org/api/console.html#console_console_log_data_args) `util.format`, which in turn [uses](https://nodejs.org/api/util.html#util_util_format_format_args) `util.inspect`, which in turn [gets](https://github.com/nodejs/node/blob/master/lib/internal/util/inspect.js#L684) the `toISOString` function from the [primordial](https://github.com/nodejs/node/blob/master/lib/internal/util/inspect.js#L6) `Date.prototype`, which means you can't override it (which is a feature because that means you can't break it, or a limitation because it means you can't customize it, depending on your point of view).