Comma is used for separation. Therefore, it cannot be at end of the sentence (ending). It must be in between of 2 entities.
When encountering a list, be in nouns, verbs, prepositional phrases, clauses and adjectives, you use comma to separate them according to their respective system.
I need to get squid, pickles, and chocolate at the grocery store.
I am going to go for a run, read a chapter of my book, and go see the new Colonel Justice movie.
Separate salutation (dear XXX) and valediction (with love, YYY) from the body of the content.
Dear Prudence,
I received your fruit.
With love,
Jaina
Dear Prudence (salutation); With Love (valediction)
Using Comma to separate the address by context.
Nero Wolfe, (recipient name)
454 W 35th Street, (house & street)
New York, (city)
NY 10001, (state and postcode)
United States of America (country)
Short use: Puchong, Selangor, Malaysia
Using Comma to separate time components like date, specific time etc.
On Tuesday (day), October 5th (date), 2010 (year), I ate a cricket.
On 5th of October (date), 2016 (year), Tuesday (day), I ate a cricket.
Using comma to separate clauses either at the beginning or the end. Normally, the beginning clause can be an adverb or prepositional phrases.
If the beginning clause is independent, you don't need to place a comma.
When you come in (dependent clause), please take off your shoes (independent).
Please take off your shoes (independent) when you come in (dependent).
I rode an elephant, and then I ate mango.
Initially, I was afraid.
Basically, I'm more confident.
Use comma to tag another object/subject in a sentence; directly addressing a subject or provide a clear emphasis.
You like cheese, don't you?
This won't hurt, will it?
Paige, how are you?
Connor, do you want to have lunch together?
No, I hate cheese.
Yes, I would love some cheese!
In dialogue, comma is used to provide a runway for the sentences. We use comma to separate the speaker sentences from the dialogue.
Guillermo said, "I have no idea where did I put that Moonstone."
"I have no idea where did I put that Moonstone," Guillermo said.
"They are probably pirate," Roxanne said.
"They are probably pirate!" Roxanne said.
"They are probably pirate?" Roxanne said.
Use comma to separate phrases or nouns that redefine or clarify its antecedent
My older sister, Griselda (clarify sister's name), is going to college in the fall.
They stopped selling my favorite snack, the cookie cat (defining the subject's favorite snack).
Oxford serial comma style requires writer to add comma before "and" when separating a list. AP style does not. It's not a right or wrong but a matter of clarity and style.
His favorite artists are Elvis, a tiny Norwegian harpist, and Frida Kahlo.
His favorite artists are Elvis, a tiny Norwegian harpist and Frida Kahlo