1. "I went to the store, and then I picked up some groceries." In this sentence, the comma is needed to separate the two independent clauses that are joined by the coordinating conjunction "and". Without the comma, the sentence would become a run-on.
2. "The dog, which was brown, barked loudly." Here, the comma is needed to set off the non-essential relative clause "which was brown". Without the comma, the sentence would imply that the dog is only brown, and the additional information about its bark becomes essential to the meaning.
3. "Yesterday, I visited New York, the city that never sleeps." In this sentence, the comma is needed to set off the non-essential appositive phrase "the city that never sleeps". Without the comma, the sentence would imply that there is only one city in the world that never sleeps, and that city is New York.