Which of these sentences is punctuated correctly?
John Quincy Adams (1767–1848) was the sixth president of the United States.
John Quincy Adams [1767–1848] was the sixth president of the United States.
John Quincy Adams, 1767–1848, was the sixth president of the United States.
John Quincy Adams—1767–1848—was the sixth president of the United States.