-
Notifications
You must be signed in to change notification settings - Fork 558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Factual error in Array Constructor chapter #192
Comments
Not true. The array has no values in it. Its length is 0 in Array(2); // false
0 in [void 0, void 0]; // true |
Even The fact that Consider this:
You'll get 2 entries in the browser console. This array has two values in it, even though they are undefined. The My original point was that this snippet of code is factually incorrect:
Passing a single Number argument to the Array constructor returns a new Array with that number of undefined indexes. Now to make things even more confusing:
Passing a non Number as the first argument does indeed create an Array with a single value. |
Trust me, the sparse array does not have those two values in it. Look at |
The very fact you and I are arguing about this behavior means it is abiguous. :) Still, you are ignoring the original post which was:
Is not correct. Passing a single number argument to the Array constructor does not create a new Array with a single number element. That is what needs to be corrected. |
Nope, it's well-defined, people are just misinformed or undereducated.
No, I agree with you on that. I just want it to be actually corrected, instead of changed to an explanation that is closer but still incorrect. |
Perhaps this was an issue in the stale version of JS Garden? I deployed the new version a few days ago, and the new discussion of the Array constructor seems correct. If that's not the case, please let me know. |
There is a factual error regarding the Array constructor when passing an argument to
new Array(...)
.The Array constructor has three overloads:
new Array()
— Results in a new, empty arraynew Array(2)
— Results in a new array with twoundefined
values in itnew Array(2, 3)
— Results in a new array with the values 2 and 3 in it.As a side note, it would be interesting to measure the difference in performance between these two pieces of code:
Empty Constructor
Predefined Length
The text was updated successfully, but these errors were encountered: