Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why new Array(4).join("ha") yields "hahahaha" and not "undefinedhaundefinedha .."

Tags:

javascript

Why new Array(4).join("ha") yields "hahaha" and not "undefinedhaundefinedha .." ?

var arr = new Array(4);
alert( arr[0] ); //  produces `undefined`
like image 558
user10777718 Avatar asked Mar 28 '19 19:03

user10777718


1 Answers

Elements of the array that are undefined or null are converted to the empty string. It's right there in the documentation.

If an element is undefined or null, it is converted to the empty string.

like image 95
Pointy Avatar answered Nov 10 '22 00:11

Pointy