Working with Arrays, Variables, and Naming Practices - How Do You Get the Length for an Array, and How Can You Create an Empty Array of Fixed Length?

Tell us what’s happening:

What will be the output of the following code?

let arr = new Array(3);
console.log(arr);

The answer should be [undefined, undefined, undefined] but isn’t?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Working with Arrays, Variables, and Naming Practices - How Do You Get the Length for an Array, and How Can You Create an Empty Array of Fixed Length?

Did you try running that code to check?

No. The curriculum says the answer is as such. It’s either the curriculum is wrong, or the answer is wrong.

1 Like

it looks like the lesson is contradicting itself

you should try to run the code when in doubt


I think the sandbox does not show sparse arrays correctly, and the example was added a comment to match that, but it’s not correct

this will need an issue created on github

2 Likes

here the issue