[Bug] new Array() - by Internet Explorer User

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

ID 836640 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/19/2014 3:59:41 AM
Access Restriction Public


1. Open F12 Developer Tools
2. Go to Console
3. Enter "new Array()" (without quotes)
4. Notice that the result is an empty array
5. Enter "new Array(2)" (without quotes)
6. Notice that the result is "[undefined, undefined]"

Entering "new Array(X)" in the Console (where X is any natural number) should ALWAYS result as an empty array (with the length of X), not an array full of "undefined" values.

Please fix this bug.
Sign in to post a comment.
Posted by Microsoft on 7/14/2014 at 11:48 AM
This behavior is by design. When you create an Array by calling the constructor with a predetermined length, you actually create a dense array with the specified number of slots. That the slots do not contain anything (therefore containing undefined) is a side effect; the following code snippets are equivalent:

var x = new Array(2);

var y = [undefined, undefined];

var z = [,];

However, this is not semantically equivalent:

var w = [];



In the original cases, the arrays have been preallocated with some number of slots. While arrays may grow, those slots are there. In the latter case, you have grown the array. While JavaScript arrays are able to grow without copying memory all of the time, if you know the size of the array that you're going to create, it is more efficient to create an array of the correct size ahead-of-time.

Best Regards,
The Internet Explorer Team
Posted by Microsoft on 3/20/2014 at 6:10 AM
Thank you for your feedback!

We will be investigating this issue further.

Best Regards,
The Internet Explorer Team