What was Barack Obama's job before being elected president of the US?

President Obama was the US senator from Illinois when he was elected President. Before that he was in the Illinois legislature and worked as a lawyer.