3/7 the mysterious comma


#1

Can anyone explain why we need a comma after closing the add method?


#2

In this section, we use object initializers. Correct syntax is:

var obj = {
    property_1: value_1,
    property_2: value_2,
    // ...
    property_n: value_n
};

It does not matter if the value of a property is a string, number, array or function (in this case we call this property a method) you have to put a comma to separate one property from the next one (that is why you don't have to put comma after the last property).


#3

@sciftci

And here a link to a good explanation in the MDN Objects