The comma in the sentence "I went to the store, but I didn't buy anything" is used to separate two independent clauses. Each clause could stand alone as a complete sentence:
- "I went to the store."
- "I didn't buy anything."
When you join two independent clauses with a coordinating conjunction (in this case, "but"), a comma is needed before the conjunction to clarify the structure of the sentence and improve readability. This helps the reader understand that there are two related but distinct thoughts being presented.