123-Essential-JavaScript-Interview-Questions icon indicating copy to clipboard operation
123-Essential-JavaScript-Interview-Questions copied to clipboard

Array question 2

Open Rishabh1208 opened this issue 4 years ago • 2 comments

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

Rishabh1208 avatar Apr 11 '20 06:04 Rishabh1208

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. :-)

ryancwalsh avatar May 10 '20 14:05 ryancwalsh

Thanks @ryancwalsh

Rishabh1208 avatar May 18 '20 12:05 Rishabh1208