Behavior of Array(n).join(s)

Rick Waldron waldron.rick at gmail.com
Mon Jul 16 13:49:37 PDT 2012


On Mon, Jul 16, 2012 at 4:39 PM, Patrick Mulder <mulder.patrick at gmail.com>wrote:

> Hello,
>
> I am rather new to ES and this group, but I am surprised by this behavior:
>
> When I do:
>
> Array(4)
> >>> [undefined, undefined, undefined, undefined]
>
> And when I do:
> >>> Array(4).join(" * ")
> " * * * "
>
> In other languages, I would not be able to join undefined objects.
> Also, if it would be, I am surprised that I get only 3 x * whereas
> above, I have 4 undefined. Anyone has some pointers, what I am
> missing?
>

Take a look at 15.4.4.5 Array.prototype.join:
http://ecma-international.org/ecma-262/5.1/#sec-15.4.4.5

Specifically, #8 explains how undefined and null are treated and #10 A-E
explain how the separator and items in the array are concatenated

Rick



>
> Thanks,
> Patrick
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120716/260ed777/attachment.html>


More information about the es-discuss mailing list