Inspired by this popular speech, I wanted to find out what the problem is with creating arrays. Let's say I create a new array using
Array(3)
In the console, I get:
[undefined, undefined, undefined]
This is pretty obvious. Say I'm doing a join to this array:
Array(3).join()
As an answer, I get:
",,"
This is also understandable, because these are three empty lines, separated by commas, I suppose. But when I try to do:
Array(3).join("lorem")
I get a line with only two lorem repeats:
"loremlorem"
Why are there two, not three repetitions of this word?
source
share