+ 2

Comma after last item in a list

In what situation(s) would it be suggested to add a comma after the last item/value in a list?

8th Feb 2018, 7:42 PM
Loren Daniel
Loren Daniel - avatar
3 ответов
+ 3
In no situaton. A comma after your last item in the list has the effect that your last item isnt anymore the last item. With comma, here will be an empty field (a hole, undefiened) the last item.
8th Feb 2018, 8:38 PM
Rainer Wess
Rainer Wess - avatar
0
IDK all the languages that do support this, but that's a new thing in JavaScript that's not even fully supported yet and will cause errors because of it in some browsers. The only good reason for it -- at least in JS -- is to make adding to the list easier in the future.
8th Feb 2018, 10:59 PM
Tom Shaver
Tom Shaver - avatar
0
Thanks all. I only ask because there was an information box on question 2 of the 'list' section for python that stated: "Most of the time, a comma won't follow the last item in a list. However, it is perfectly valid to place one there, and it is encouraged in some cases."
8th Feb 2018, 11:22 PM
Loren Daniel
Loren Daniel - avatar