ganqqwerty / 123-Essential-JavaScript-Interview-Questions

JavaScript interview Questions
BSD 3-Clause "New" or "Revised" License
5.01k stars 1.18k forks source link

Array question 2 #91

Open Rishabh1208 opened 4 years ago

Rishabh1208 commented 4 years ago

In the Array topic, the answer to question2 is wrong. It should be 2 i.e ([] [undefined × 100] Array[5] 1)

ryancwalsh commented 4 years ago

I agree that https://github.com/ganqqwerty/123-Essential-JavaScript-Interview-Questions#2-what-would-be-the-output-of-following-code-2 is incorrect.

(function() {
    var array1 = [];
    var array2 = new Array(100);
    var array3 = new Array(['1',2,'3',4,5.6]);
    console.log(array1);
    console.log(array2);
    console.log(array3);
    console.log(array3.length);
}());

But to clarify what @Rishabh1208 is saying...

For me, in Windows Chrome, the result is:

[]
[empty × 100]
[["1", 2, "3", 4, 5.6]]
1

Thanks for a really helpful long list of thought-provoking questions, though. :-)

Rishabh1208 commented 4 years ago

Thanks @ryancwalsh