The general purpose of a comma is to separate closely related but distinct elements in a sentence. Discussion of three specific functions of the comma follows:
1. Place Names and Dates
A pair of commas sets a more widely encompassing place name off from the more specific designation of a place within the other location, as in “She was born in Pensacola, Florida, in 1980.” Likewise, a reference to a year is set off from the rest of the sentence when it follows a reference to a month and day (but not to the month alone), as in “She was born on January 1, 1980, in Pensacola” (but “She was born in January 1980 in Pensacola”).
When the items in a list of locations require internal commas, the items should be set off by semicolons: “I’ve participated in events with him in Kansas City, Missouri; Rapid City, South Dakota; and Oak Park, Illinois.” However, if only one of the items requires an internal comma, place it last in the series and rely on commas to distinguish the items: “I’ve participated in events with him in New York City, San Francisco, and Bloomington, Indiana.”
But if such a list requires a scheme of priority, such as chronological or geographical order, retain semicolons: “I’ve participated in events with him in Bloomington, Indiana; San Francisco; and New York City.” Alternatively, for the sake of simplicity, set the more complex item apart from the simpler ones: “I’ve participated in events with him in San Francisco and New York City, as well as in Bloomington, Indiana.”)
2. Examples and Definitions
Words or phrases that identify a preceding or following example or definition, or that constitute a definition or explanation, should be framed in commas, as in these examples:
“The series features mysteries, thrillers, etc., presented throughout the summer.”
“I would, for example, clean the gasket before attaching it.”
“They then established a cache, or a hiding place, for their supplies.”
For clarity, however, it’s sometimes best to set off a preceding abbreviation, word, or phrase between em dashes (or parentheses), as shown in this example:
“I like books in the action genres — i.e., stories with chase scenes, gunfights, and so on — though characterization and plot are also important to me.”
3. Direct Address
When a writer or speaker directs a descriptive word or phrase for one or more readers or audience members to that target, the description is set off from the rest of the statement.
“Attention, all passengers — we will begin boarding procedures soon.”
“I am confident, dear reader, that when you have finished this story, you will agree with me.”