Your examples are two different things. The first example creates three separate Date objects, which can have three different dates.

The second example creates one Date object, which var1, var2, and var3 point to. When you change the Date object, var1, var2, and var3 will all see that change.

Answer from Edwin Torres on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date › Date
Date() constructor - JavaScript | MDN
The Date() constructor creates Date objects. When called as a function, it returns a string representing the current time. const date1 = new Date("December 17, 1995 03:24:00"); // Sun Dec 17 1995 03:24:00 GMT... const date2 = new Date("1995-12-17T03:24:00"); // Sun Dec 17 1995 03:24:00 GMT... ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Date
Date - JavaScript | MDN
Returns a string representing the ... by JSON.stringify(). ... Returns a string with a locality sensitive representation of the date portion of this date based on system settings. ... Returns a string with a locality-sensitive representation of this date. Overrides the Object.prototype...
🌐
W3Schools
w3schools.com › js › js_dates.asp
W3Schools.com
By default, JavaScript will use the browser's time zone and display a date as a full text string: You will learn much more about how to display dates, later in this tutorial. Date objects are created with the new Date() constructor.
🌐
W3Schools
w3schools.com › jsref › jsref_date_new.asp
JavaScript new Date Method
cssText getPropertyPriority() ... time = new Date(); Try it Yourself » · More Examples Below ! The new Date() constructor creates a new Date object....
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Date and time
To create a new Date object call new Date() with one of the following arguments:
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Representing_dates_times
Representing dates & times - JavaScript | MDN
A set of integer values for year, month, day, hour, minute, and seconds. For example, xmas95 = new Date(1995, 11, 25, 9, 30, 0);. The Date object methods for handling dates and times fall into these broad categories:
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-date-objects
JavaScript Date Objects - GeeksforGeeks
July 11, 2025 - You can pass a date string to the constructor to create a Date object for a specific date and time. ... The Date constructor can also take individual parameters for year, month (0-indexed), day, hour, minute, second, and millisecond.
🌐
Talent500
talent500.com › blog › javascript-date-object-methods-time-zones
JavaScript Date Object: Methods, Time Zones & Usage Guide
June 17, 2025 - In this example, new Date() creates a Date object that holds the current date and time based on the computer clock where your JavaScript code is running. However, if you run these same code snippets in different environments, you will see different ...
Find elsewhere
🌐
CodingNomads
codingnomads.com › introduction-javascript-date-object
Beginners Guide to the Date Object in JavaScript
The global Date object is like ... information itself. When you create an instance of a Date by using the new Date() instantiation syntax, you're creating an object that represents a specific point in time....
🌐
W3Schools
w3schools.com › jsref › jsref_obj_date.asp
JavaScript Date Reference
Boolean() new Boolean() constructor prototype toString() valueOf() JS Classes ... new Date() constructor getDate() getDay() getFullYear() getHours() getMilliseconds() getMinutes() getMonth() getSeconds() getTime() getTimezoneOffset() getUTCDate() getUTCDay() getUTCFullYear() getUTCHours() getUTCMilliseconds() getUTCMinutes() getUTCMonth() getUTCSeconds() now() parse() prototype setDate() setFullYear() setHours() setMilliseconds() setMinutes() setMonth() setSeconds() setTime() setUTCDate() setUTCFullYear() setUTCHours() setUTCMilliseconds() setUTCMinutes() setUTCMonth() setUTCSeconds() toDateString() toISOString() toJSON() toLocaleDateString() toLocaleTimeString() toLocaleString() toString() toTimeString() toUTCString() UTC() valueOf() JS Function
Top answer
1 of 3
3

The first example results in an object with keys based on the user's locale's string representation for dates, each containing the same value as a Date object. This is not particularly useful, in part because the keys will differ depending on the user's locale, and because in order to access the value of one of those keys, you would need to know the date that matches it... which is the value you'd be looking up in the first place.

The second example results in an empty object (because it just references each "key", without assigning a value to it.)

Copyvar eventDates = {};
eventDates[new Date('10/04/2017')] = new Date('10/04/2017');
eventDates[new Date('10/06/2017')] = new Date('10/06/2017');
eventDates[new Date('10/20/2017')] = new Date('10/20/2017');
eventDates[new Date('10/26/2017')] = new Date('10/26/2017');
console.log(eventDates);

var eventDates2 = {};
eventDates2[new Date('10/04/2017')];
eventDates2[new Date('10/06/2017')];
eventDates2[new Date('10/20/2017')];
eventDates2[new Date('10/26/2017')];

console.log(eventDates2)
Run code snippetEdit code snippet Hide Results Copy to answer Expand

It's not clear to me what the author of either of these examples was trying to accomplish. If you really wanted an array of dates, you would instead do this:

Copyvar eventDatesArray = [];
eventDatesArray.push(new Date('10/04/2017'));
eventDatesArray.push(new Date('10/06/2017'));
eventDatesArray.push(new Date('10/20/2017'));
eventDatesArray.push(new Date('10/26/2017'));

console.log(eventDatesArray);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

2 of 3
1

It'not the same. In the first array you are setting the new Date object to be the key and the value of the array.

In the second you are setting just the key.

example: Lets say you have an array , array = {};

If you wanna set the key of the array you do it like this.

Copyarray['key1'] = someValue1;
array['key2'] = someValue2;
array['key3'] = someValue3;

And then you can get these values with each key.

Copyvar variable1 = array['key1'];

Now if you console.log this variable1 you get someValue1

Copylet array1 = {};

array1['key1'] = 1;
array1['key2'] = 2;
array1['key2'] = 3;

let array2 = {};

array2['key1'];
array2['key2'];
array2['key2'];

console.log('First Array',array1['key1']);
console.log('First Array',array2['key1']);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript date object
JavaScript Date Object
September 1, 2008 - The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ) as shown below.
🌐
SheCodes
shecodes.io › athena › 77519-what-is-new-date-in-javascript
[JavaScript] - What is new date() in JavaScript? - SheCodes | SheCodes
Learn about the new Date() function in JavaScript and how it is used to work with dates and times in JavaScript.
🌐
W3Schools
w3schools.com › js › js_date_methods.asp
JavaScript Get Date Methods
JS Examples JS HTML DOM JS HTML ... Prep JS Bootcamp JS Certificate JS Reference ... In JavaScript, date objects are created with new Date()....
🌐
Bugfender
bugfender.com › blog › javascript-date-and-time
The Definitive Guide to JavaScript Date and Time | Bugfender
February 18, 2025 - It is used for converting between Date JS objects and epoch timestamps and performing other advanced operations​. The most common way to create a Date object in JavaScript is by using the new Date() constructor, which returns the current date ...