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:

The answer to the question in quiz:
2. What will be the output of the following code?

let arr = new Array(3);
console.log(arr);
is [<3 empty items>]

Shouldn’t it be: [undefined, undefined, undefined]

like stated in the example above:
const emptyArray = new Array(5);
console.log(emptyArray.length); // 5
console.log(emptyArray); // [undefined, undefined, undefined, undefined, undefined]
Correct me if I’m wrong please.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:144.0) Gecko/20100101 Firefox/144.0

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?

Welcome to the forum @Eryk .

If you create an array using new Array(3) in your browser’s console, you will see [empty x 3]. But creating the array using Array.from({length: 3}) produces [undefined, undefined, undefined]. So, it looks like this lecture needs to be edited to show the logs correctly.

You can create an issue for this at GitHub · Where software is built